|
7 | 7 | import { |
8 | 8 | createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, ServerCapabilities, ConfigurationRequest, WorkspaceFolder |
9 | 9 | } from 'vscode-languageserver'; |
10 | | - |
| 10 | +import URI from 'vscode-uri'; |
11 | 11 | import { TextDocument, CompletionList } from 'vscode-languageserver-types'; |
12 | 12 |
|
13 | 13 | import { getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService, LanguageSettings, LanguageService, Stylesheet } from 'vscode-css-languageservice'; |
14 | 14 | import { getLanguageModelCache } from './languageModelCache'; |
15 | | -import { formatError, runSafe } from './utils/runner'; |
16 | | -import URI from 'vscode-uri'; |
17 | 15 | import { getPathCompletionParticipant } from './pathCompletion'; |
| 16 | +import { formatError, runSafe } from './utils/runner'; |
| 17 | +import { getDocumentContext } from './utils/documentContext'; |
18 | 18 |
|
19 | 19 | export interface Settings { |
20 | 20 | css: LanguageSettings; |
@@ -86,6 +86,9 @@ connection.onInitialize((params: InitializeParams): InitializeResult => { |
86 | 86 | referencesProvider: true, |
87 | 87 | definitionProvider: true, |
88 | 88 | documentHighlightProvider: true, |
| 89 | + documentLinkProvider: { |
| 90 | + resolveProvider: false |
| 91 | + }, |
89 | 92 | codeActionProvider: true, |
90 | 93 | renameProvider: true, |
91 | 94 | colorProvider: {}, |
@@ -227,29 +230,43 @@ connection.onDocumentSymbol((documentSymbolParams, token) => { |
227 | 230 | }, [], `Error while computing document symbols for ${documentSymbolParams.textDocument.uri}`, token); |
228 | 231 | }); |
229 | 232 |
|
230 | | -connection.onDefinition((documentSymbolParams, token) => { |
| 233 | +connection.onDefinition((documentDefinitionParams, token) => { |
231 | 234 | return runSafe(() => { |
232 | | - const document = documents.get(documentSymbolParams.textDocument.uri); |
| 235 | + const document = documents.get(documentDefinitionParams.textDocument.uri); |
233 | 236 | if (document) { |
234 | 237 |
|
235 | 238 | const stylesheet = stylesheets.get(document); |
236 | | - return getLanguageService(document).findDefinition(document, documentSymbolParams.position, stylesheet); |
| 239 | + return getLanguageService(document).findDefinition(document, documentDefinitionParams.position, stylesheet); |
237 | 240 | } |
238 | 241 | return null; |
239 | | - }, null, `Error while computing definitions for ${documentSymbolParams.textDocument.uri}`, token); |
| 242 | + }, null, `Error while computing definitions for ${documentDefinitionParams.textDocument.uri}`, token); |
240 | 243 | }); |
241 | 244 |
|
242 | | -connection.onDocumentHighlight((documentSymbolParams, token) => { |
| 245 | +connection.onDocumentHighlight((documentHighlightParams, token) => { |
243 | 246 | return runSafe(() => { |
244 | | - const document = documents.get(documentSymbolParams.textDocument.uri); |
| 247 | + const document = documents.get(documentHighlightParams.textDocument.uri); |
| 248 | + if (document) { |
| 249 | + const stylesheet = stylesheets.get(document); |
| 250 | + return getLanguageService(document).findDocumentHighlights(document, documentHighlightParams.position, stylesheet); |
| 251 | + } |
| 252 | + return []; |
| 253 | + }, [], `Error while computing document highlights for ${documentHighlightParams.textDocument.uri}`, token); |
| 254 | +}); |
| 255 | + |
| 256 | + |
| 257 | +connection.onDocumentLinks((documentLinkParams, token) => { |
| 258 | + return runSafe(() => { |
| 259 | + const document = documents.get(documentLinkParams.textDocument.uri); |
245 | 260 | if (document) { |
| 261 | + const documentContext = getDocumentContext(document.uri, workspaceFolders); |
246 | 262 | const stylesheet = stylesheets.get(document); |
247 | | - return getLanguageService(document).findDocumentHighlights(document, documentSymbolParams.position, stylesheet); |
| 263 | + return getLanguageService(document).findDocumentLinks(document, stylesheet, documentContext); |
248 | 264 | } |
249 | 265 | return []; |
250 | | - }, [], `Error while computing document highlights for ${documentSymbolParams.textDocument.uri}`, token); |
| 266 | + }, [], `Error while computing document links for ${documentLinkParams.textDocument.uri}`, token); |
251 | 267 | }); |
252 | 268 |
|
| 269 | + |
253 | 270 | connection.onReferences((referenceParams, token) => { |
254 | 271 | return runSafe(() => { |
255 | 272 | const document = documents.get(referenceParams.textDocument.uri); |
|
0 commit comments