mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 17:48:56 +01:00
Move md path completions and document links to language server (#155100)
This commit is contained in:
@@ -3,27 +3,35 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Connection, InitializeParams, InitializeResult, TextDocuments } from 'vscode-languageserver';
|
||||
import { Connection, InitializeParams, InitializeResult, NotebookDocuments, TextDocuments } from 'vscode-languageserver';
|
||||
import { TextDocument } from 'vscode-languageserver-textdocument';
|
||||
import * as lsp from 'vscode-languageserver-types';
|
||||
import * as md from 'vscode-markdown-languageservice';
|
||||
import { URI } from 'vscode-uri';
|
||||
import { LogFunctionLogger } from './logging';
|
||||
import { parseRequestType } from './protocol';
|
||||
import { VsCodeClientWorkspace } from './workspace';
|
||||
|
||||
declare const TextDecoder: any;
|
||||
|
||||
export function startServer(connection: Connection) {
|
||||
export async function startServer(connection: Connection) {
|
||||
const documents = new TextDocuments(TextDocument);
|
||||
documents.listen(connection);
|
||||
const notebooks = new NotebookDocuments(documents);
|
||||
|
||||
connection.onInitialize((_params: InitializeParams): InitializeResult => {
|
||||
connection.onInitialize((params: InitializeParams): InitializeResult => {
|
||||
workspace.workspaceFolders = (params.workspaceFolders ?? []).map(x => URI.parse(x.uri));
|
||||
return {
|
||||
capabilities: {
|
||||
documentLinkProvider: { resolveProvider: true },
|
||||
documentSymbolProvider: true,
|
||||
completionProvider: { triggerCharacters: ['.', '/', '#'] },
|
||||
foldingRangeProvider: true,
|
||||
selectionRangeProvider: true,
|
||||
workspaceSymbolProvider: true,
|
||||
workspace: {
|
||||
workspaceFolders: {
|
||||
supported: true,
|
||||
changeNotifications: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -36,15 +44,36 @@ export function startServer(connection: Connection) {
|
||||
}
|
||||
};
|
||||
|
||||
const workspace = new VsCodeClientWorkspace(connection, documents);
|
||||
const workspace = new VsCodeClientWorkspace(connection, documents, notebooks);
|
||||
const logger = new LogFunctionLogger(connection.console.log.bind(connection.console));
|
||||
const provider = md.createLanguageService({ workspace, parser, logger });
|
||||
|
||||
connection.onDocumentLinks(async (params, token): Promise<lsp.DocumentLink[]> => {
|
||||
try {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
if (document) {
|
||||
return await provider.getDocumentLinks(document, token);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
connection.onDocumentLinkResolve(async (link, token): Promise<lsp.DocumentLink | undefined> => {
|
||||
try {
|
||||
return await provider.resolveDocumentLink(link, token);
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
connection.onDocumentSymbol(async (params, token): Promise<lsp.DocumentSymbol[]> => {
|
||||
try {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
if (document) {
|
||||
return await provider.provideDocumentSymbols(document, token);
|
||||
return await provider.getDocumentSymbols(document, token);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
@@ -56,7 +85,7 @@ export function startServer(connection: Connection) {
|
||||
try {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
if (document) {
|
||||
return await provider.provideFoldingRanges(document, token);
|
||||
return await provider.getFoldingRanges(document, token);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
@@ -68,7 +97,7 @@ export function startServer(connection: Connection) {
|
||||
try {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
if (document) {
|
||||
return await provider.provideSelectionRanges(document, params.positions, token);
|
||||
return await provider.getSelectionRanges(document, params.positions, token);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
@@ -78,13 +107,26 @@ export function startServer(connection: Connection) {
|
||||
|
||||
connection.onWorkspaceSymbol(async (params, token): Promise<lsp.WorkspaceSymbol[]> => {
|
||||
try {
|
||||
return await provider.provideWorkspaceSymbols(params.query, token);
|
||||
return await provider.getWorkspaceSymbols(params.query, token);
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
connection.onCompletion(async (params, token): Promise<lsp.CompletionItem[]> => {
|
||||
try {
|
||||
const document = documents.get(params.textDocument.uri);
|
||||
if (document) {
|
||||
return await provider.getCompletionItems(document, params.position, params.context!, token);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
documents.listen(connection);
|
||||
notebooks.listen(connection);
|
||||
connection.listen();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user