Add optional markdown occurrences highlighting (#164292)

Fixes #164290
This commit is contained in:
Matt Bierner 2022-10-21 14:19:50 -07:00 committed by GitHub
parent f941ff6566
commit b11bb04298
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 15 deletions

View file

@ -566,6 +566,12 @@
"tags": [
"experimental"
]
},
"markdown.occurrencesHighlight.enabled": {
"type": "boolean",
"default": false,
"description": "%configuration.markdown.occurrencesHighlight.enabled%",
"scope": "resource"
}
}
},

View file

@ -46,6 +46,7 @@
"configuration.markdown.updateLinksOnFileMove.enabled.always": "Always update links automatically.",
"configuration.markdown.updateLinksOnFileMove.enabled.never": "Never try to update link and don't prompt.",
"configuration.markdown.updateLinksOnFileMove.fileGlobs": "A glob that specifies which files besides markdown should trigger a link update.",
"configuration.markdown.updateLinksOnFileMove.enableForDirectories": "enable/disable updating links when a directory is moved or renamed in the workspace.",
"configuration.markdown.updateLinksOnFileMove.enableForDirectories": "Enable/disable updating links when a directory is moved or renamed in the workspace.",
"configuration.markdown.occurrencesHighlight.enabled": "Enable/disable highlighting link occurrences in the current document.",
"workspaceTrust": "Required for loading styles configured in the workspace."
}

View file

@ -13,7 +13,7 @@
"vscode-languageserver": "^8.0.2",
"vscode-languageserver-textdocument": "^1.0.5",
"vscode-languageserver-types": "^3.17.1",
"vscode-markdown-languageservice": "^0.2.0-alpha.2",
"vscode-markdown-languageservice": "^0.2.0-alpha.3",
"vscode-nls": "^5.2.0",
"vscode-uri": "^3.0.3"
},

View file

@ -10,6 +10,10 @@ export type ValidateEnabled = 'ignore' | 'warning' | 'error' | 'hint';
interface Settings {
readonly markdown: {
readonly occurrencesHighlight: {
readonly enabled: boolean;
};
readonly suggest: {
readonly paths: {
readonly enabled: boolean;

View file

@ -79,6 +79,7 @@ export async function startServer(connection: Connection, serverConfig: {
});
registerCompletionsSupport(connection, documents, mdLs, configurationManager);
registerDocumentHightlightSupport(connection, documents, mdLs, configurationManager);
registerValidateSupport(connection, workspace, documents, mdLs, configurationManager, serverConfig.logger);
return {
@ -93,7 +94,7 @@ export async function startServer(connection: Connection, serverConfig: {
completionProvider: { triggerCharacters: ['.', '/', '#'] },
definitionProvider: true,
documentLinkProvider: { resolveProvider: true },
documentHighlightProvider: false, // TODO: Disabling for now
documentHighlightProvider: true,
documentSymbolProvider: true,
foldingRangeProvider: true,
referencesProvider: true,
@ -233,14 +234,6 @@ export async function startServer(connection: Connection, serverConfig: {
return codeAction;
});
connection.onDocumentHighlight(async (params, token) => {
const document = documents.get(params.textDocument.uri);
if (!document) {
return undefined;
}
return mdLs!.getDocumentHighlights(document, params.position, token);
});
connection.onRequest(protocol.getReferencesToFileInWorkspace, (async (params: { uri: string }, token: CancellationToken) => {
return mdLs!.getFileReferences(URI.parse(params.uri), token);
}));
@ -308,3 +301,24 @@ function registerCompletionsSupport(
update();
return config.onDidChangeConfiguration(() => update());
}
function registerDocumentHightlightSupport(
connection: Connection,
documents: TextDocuments<md.ITextDocument>,
mdLs: md.IMdLanguageService,
configurationManager: ConfigurationManager
) {
connection.onDocumentHighlight(async (params, token) => {
const settings = configurationManager.getSettings();
if (!settings?.markdown.occurrencesHighlight.enabled) {
return undefined;
}
const document = documents.get(params.textDocument.uri);
if (!document) {
return undefined;
}
return mdLs!.getDocumentHighlights(document, params.position, token);
});
}

View file

@ -42,10 +42,10 @@ vscode-languageserver@^8.0.2:
dependencies:
vscode-languageserver-protocol "3.17.2"
vscode-markdown-languageservice@^0.2.0-alpha.2:
version "0.2.0-alpha.2"
resolved "https://registry.yarnpkg.com/vscode-markdown-languageservice/-/vscode-markdown-languageservice-0.2.0-alpha.2.tgz#ed08bc3f7f19c5fb0283547a7855542224ce377c"
integrity sha512-2/Mp/b63ohC8k0h1boWohf2G6SwLb3IA+c3UcqPs4FdaRpGqpf2wVXaT5aQ5qVRGpqvCwfyyyr2YEdqwuQc5KA==
vscode-markdown-languageservice@^0.2.0-alpha.3:
version "0.2.0-alpha.3"
resolved "https://registry.yarnpkg.com/vscode-markdown-languageservice/-/vscode-markdown-languageservice-0.2.0-alpha.3.tgz#5bc3934ebb97ce855f49fbb345a5e1f5ace7d660"
integrity sha512-3ikmh1Mcr9s5s0wZZsxb7heSzKooudCgtZzL5d8t94WDbg02u9i2cDYF6qufK6Og5pBSC3ajeF12qFAYbRIbgQ==
dependencies:
picomatch "^2.3.1"
vscode-languageserver-textdocument "^1.0.5"