Skip to content

Commit

Permalink
feat: implement definitions for markdown (#71)
Browse files Browse the repository at this point in the history
This was already supported by `vscode-markdown-languageservice`, but not
implemented by `volar-service-markdown`.

Co-authored-by: Johnson Chu <johnsoncodehk@gmail.com>
  • Loading branch information
remcohaszing and johnsoncodehk authored Jan 21, 2024
1 parent 9467927 commit 9cf0af8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/markdown/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forEachEmbeddedCode, type FileChangeType, type FileType, type ServicePlugin, ServicePluginInstance } from '@volar/language-service';
import { ServicePluginInstance, forEachEmbeddedCode, type FileChangeType, type FileType, type LocationLink, type ServicePlugin } from '@volar/language-service';
import { Emitter } from 'vscode-jsonrpc';
import type { TextDocument } from 'vscode-languageserver-textdocument';
import type { DiagnosticOptions, ILogger, IMdLanguageService, IMdParser, IWorkspace } from 'vscode-markdown-languageservice';
Expand Down Expand Up @@ -240,6 +240,26 @@ export function create(options: CreateOptions): ServicePlugin {
}
},

async provideDefinition(document, position, token) {
if (prepare(document)) {
let locations = await ls.getDefinition(document, position, token);

if (!locations) {
return;
}

if (!Array.isArray(locations)) {
locations = [locations];
}

return locations.map<LocationLink>(location => ({
targetUri: location.uri,
targetRange: location.range,
targetSelectionRange: location.range,
}));
}
},

async provideDiagnostics(document, token) {
if (prepare(document)) {
const configuration = await getConfiguration?.(options.configurationSection, document.uri);
Expand Down

0 comments on commit 9cf0af8

Please sign in to comment.