Skip to content

Commit 52d10ae

Browse files
authored
add workspace/xreferences extension (#8)
* add workspace/reference extension
1 parent ea634d2 commit 52d10ae

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

extension-workspace-references.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# workspace/xreferences extension to LSP
2+
3+
The `workspace/xreferences` extension to the Language Server Protocol (LSP) enables a language server to export all of the references made from the workspace's code to its dependencies. Additionally, a new `textDocument/xdefinition` method performs the equivalent of `textDocument/definition` while returning metadata about the definition and _optionally_ a concrete location to it.
4+
5+
Use case: clients of a language server can invoke `workspace/xreferences` in order to find references to dependencies. This information can then be stored in a database, which allows the caller to create a "global mapping" of symbols in dependencies to the workspaces they are used in (e.g. to see "how do other people use this symbol?"). A user would perform `textDocument/xdefinition` in order to locate the metadata about the symbol they are interested in and find its references in the database.
6+
7+
### Initialization
8+
9+
`ServerCapabilities` may contain a new field to indicate server-side support for this extension:
10+
11+
```typescript
12+
interface ServerCapabilities {
13+
/* ... all fields from the base ServerCapabilities ... */
14+
15+
/**
16+
* The server provides workspace references exporting support.
17+
*/
18+
xworkspaceReferencesProvider?: boolean;
19+
20+
/**
21+
* The server provides extended text document definition support.
22+
*/
23+
xdefinitionProvider?: boolean;
24+
}
25+
```
26+
27+
#### Workspace References Request
28+
29+
The workspace references request is sent from the client to the server to locate project-wide references to a symbol given its description / metadata.
30+
31+
_Request_
32+
* method: 'workspace/xreferences'
33+
* params: `WorkspaceReferencesParams` defined as follows:
34+
```typescript
35+
/**
36+
* The parameters of a Workspace References Request.
37+
*/
38+
interface WorkspaceReferencesParams {
39+
/**
40+
* Metadata about the symbol that is being searched for.
41+
*/
42+
query: SymbolDescriptor;
43+
44+
/**
45+
* An optional list of files to restrict the search to.
46+
*/
47+
files?: string[];
48+
}
49+
```
50+
51+
_Response_:
52+
* result: `ReferenceInformation[]` defined as follows:
53+
```typescript
54+
/**
55+
* Represents information about a reference to programming constructs like
56+
* variables, classes, interfaces, etc.
57+
*/
58+
interface ReferenceInformation {
59+
/**
60+
* The location in the workspace where the `symbol` is referenced.
61+
*/
62+
reference: Location;
63+
64+
/**
65+
* Metadata about the symbol that can be used to identify or locate its
66+
* definition.
67+
*/
68+
symbol: SymbolDescriptor;
69+
}
70+
```
71+
* error: code and message set in case an exception happens during the workspace references request.
72+
73+
Where `SymbolDescriptor` is defined as follows:
74+
75+
```typescript
76+
/**
77+
* Represents information about a programming construct that can be used to
78+
* identify and locate the construct's symbol. The identification does not have
79+
* to be unique, but it should be as unique as possible. It is up to the
80+
* language server to define the schema of this object.
81+
*
82+
* In contrast to `SymbolInformation`, `SymbolDescriptor` includes more concrete,
83+
* language-specific, metadata about the symbol.
84+
*/
85+
interface SymbolDescriptor {
86+
/**
87+
* A list of properties of a symbol that can be used to identify or locate
88+
* it.
89+
*/
90+
[attr: string]: any
91+
}
92+
```
93+
94+
### Goto Definition Extension Request
95+
96+
This method is the same as `textDocument/definition`, except that:
97+
98+
1. The method returns metadata about the definition (the same metadata that `workspace/xreferences` searches for).
99+
2. The concrete location to the definition (`location` field) is optional. This is useful because the language server might not be able to resolve a goto definition request to a concrete location (e.g. due to lack of dependencies) but still may know _some_ information about it.
100+
101+
_Request_
102+
* method: 'textDocument/xdefinition'
103+
* params: [`TextDocumentPositionParams`](#textdocumentpositionparams)
104+
105+
_Response_:
106+
* result: `SymbolLocationInformation[]` defined as follows:
107+
```typescript
108+
interface SymbolLocationInformation {
109+
/* The location where the symbol is defined, if any. */
110+
location?: Location;
111+
112+
/**
113+
* Metadata about the symbol that can be used to identify or locate its
114+
* definition.
115+
*/
116+
symbol: SymbolDescriptor;
117+
}
118+
```
119+
* error: code and message set in case an exception happens during the definition request.

0 commit comments

Comments
 (0)