| 1 | package lspext |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "sort" |
| 6 | "strings" |
| 7 | ) |
| 8 | |
| 9 | // WorkspacePackagesParams is parameters for the `workspace/xpackages` extension. |
| 10 | // |
| 11 | // See: https://github.com/sourcegraph/language-server-protocol/blob/7fd3c1/extension-workspace-references.md |
| 12 | type WorkspacePackagesParams struct{} |
| 13 | |
| 14 | // PackageInformation is the metadata associated with a build-system- |
| 15 | // or package-manager-level package. Sometimes, languages have |
| 16 | // abstractions called "packages" as well, but this refers |
| 17 | // specifically to packages as defined by the build system or package |
| 18 | // manager. E.g., Python pip packages (NOT Python language packages or |
| 19 | // modules), Go packages, Maven packages (NOT Java language packages), |
| 20 | // npm modules (NOT JavaScript language modules). PackageInformation |
| 21 | // includes both attributes of the package itself and attributes of |
| 22 | // the package's dependencies. |
| 23 | type PackageInformation struct { |
| 24 | // Package is the set of attributes of the package |
| 25 | Package PackageDescriptor `json:"package,omitempty"` |
| 26 | |
| 27 | // Dependencies is the list of dependency attributes |
| 28 | Dependencies []DependencyReference `json:"dependencies,omitempty"` |
| 29 | } |
| 30 | |
| 31 | // PackageDescriptor identifies a package (usually but not always uniquely). |
| 32 | type PackageDescriptor map[string]interface{} |
| 33 | |
| 34 | // String returns a consistently ordered string representation of the |
| 35 | // PackageDescriptor. It is useful for testing. |
| 36 | func (s PackageDescriptor) String() string { |
| 37 | sm := make(sortedMap, 0, len(s)) |
| 38 | for k, v := range s { |
| 39 | sm = append(sm, mapValue{key: k, value: v}) |
| 40 | } |
| 41 | sort.Sort(sm) |
| 42 | var str string |
| 43 | for _, v := range sm { |
| 44 | str += fmt.Sprintf("%s:%v ", v.key, v.value) |
| 45 | } |
| 46 | return strings.TrimSpace(str) |
| 47 | } |