mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
Goto definition for DOM classes in HTML
This commit is contained in:
@@ -15,6 +15,8 @@ import { HTMLDocumentRegions } from './embeddedSupport';
|
|||||||
|
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { getSemanticTokens, getSemanticTokenLegend } from './javascriptSemanticTokens';
|
import { getSemanticTokens, getSemanticTokenLegend } from './javascriptSemanticTokens';
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
const JS_WORD_REGEX = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g;
|
const JS_WORD_REGEX = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g;
|
||||||
|
|
||||||
@@ -302,11 +304,19 @@ export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocume
|
|||||||
const jsLanguageService = await host.getLanguageService(jsDocument);
|
const jsLanguageService = await host.getLanguageService(jsDocument);
|
||||||
const definition = jsLanguageService.getDefinitionAtPosition(jsDocument.uri, jsDocument.offsetAt(position));
|
const definition = jsLanguageService.getDefinitionAtPosition(jsDocument.uri, jsDocument.offsetAt(position));
|
||||||
if (definition) {
|
if (definition) {
|
||||||
return definition.filter(d => d.fileName === jsDocument.uri).map(d => {
|
return definition.filter(d => d.fileName === jsDocument.uri || d.fileName === 'lib.dom.d.ts').map(d => {
|
||||||
return {
|
if (d.fileName === jsDocument.uri) {
|
||||||
uri: document.uri,
|
return {
|
||||||
range: convertRange(jsDocument, d.textSpan)
|
uri: document.uri,
|
||||||
};
|
range: convertRange(jsDocument, d.textSpan)
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const [libDomUri, libDomDocument] = getLibDomUriAndDocument();
|
||||||
|
return {
|
||||||
|
uri: libDomUri,
|
||||||
|
range: convertRange(libDomDocument, d.textSpan)
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -601,3 +611,11 @@ function generateIndent(level: number, options: FormattingOptions) {
|
|||||||
return repeat('\t', level);
|
return repeat('\t', level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLibDomUriAndDocument(): [string, TextDocument] {
|
||||||
|
const folderName = path.dirname(path.dirname(path.dirname(path.dirname(__dirname))));
|
||||||
|
const filepath = path.resolve(folderName, 'node_modules', 'typescript', 'lib', 'lib.dom.d.ts');
|
||||||
|
const fileUri = `file:///${filepath}`;
|
||||||
|
const content = fs.readFileSync(filepath, 'utf8');
|
||||||
|
return [fileUri, TextDocument.create(fileUri, 'typescript', 1, content)];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user