Go to defination: go to included module/file

This commit is contained in:
全卓 2022-11-10 20:42:06 +08:00
parent 9f1c592e70
commit a49108bea3
3 changed files with 34 additions and 5 deletions

View File

@ -294,8 +294,8 @@ function getWordAtPosition(textDocument: TextDocument, position: Position): Word
start = line.substring(0, position.character),
end = line.substring(position.character);
// TODO: the regex expression capture numbers, fix it.
const startReg = /[a-zA-Z0-9_]*$/,
endReg = /^[a-zA-Z0-9_]*/;
const startReg = /[a-zA-Z0-9_\.\/]*$/,
endReg = /^[a-zA-Z0-9_\.\/]*/;
const startWord = start.match(startReg)[0],
endWord = end.match(endReg)[0];

View File

@ -80,6 +80,24 @@ export class DefinationListener extends CMakeListener {
if (!fileUri) {
return;
}
// add included module to refDef
const refPos: string = this.uri + '_' + (nameToken.line - 1) + '_' +
nameToken.column + '_' + nameToken.text;
refToDef.set(refPos, {
uri: fileUri,
range: {
start: {
line: 0,
character: 0
},
end: {
line: Number.MAX_VALUE,
character: Number.MAX_VALUE
}
}
});
const tree = getFileContext(fileUri);
const definationListener = new DefinationListener(fileUri, this.currentScope);
antlr4.tree.ParseTreeWalker.DEFAULT.walk(definationListener, tree);

View File

@ -68,6 +68,10 @@ export function getIncludeFileUri(currentFileUri: string, includeFileName: strin
return includeFileUri;
}
// TODO: if includeFileName contains variable reference
// ex: include(${CMAKE_CURRENT_LIST_DIR}/xxx.cmake)
// Module: AndroidTestUtilities
// name is a cmake module
const cmakePath: string = which('cmake');
if (cmakePath === null) {
@ -75,20 +79,27 @@ export function getIncludeFileUri(currentFileUri: string, includeFileName: strin
}
const moduleDir = 'cmake-' + cmakeVersion.major + '.' + cmakeVersion.minor;
const resPath = path.join(cmakePath, '..', 'share', moduleDir, 'Modules', includeFileName) + '.cmake';
const resPath = path.join(cmakePath, '../..', 'share', moduleDir, 'Modules', includeFileName) + '.cmake';
return pathToFileURL(resPath).toString();
if (existsSync(resPath)) {
return pathToFileURL(resPath).toString();
}
return null;
}
function which(cmd: string): string {
let command: string;
let pathEnvSep: string;
if (os.type() === 'Windows_NT') {
command = cmd + ".exe";
pathEnvSep = ';';
} else {
command = cmd;
pathEnvSep = ':';
}
for (const dir of process.env.PATH.split(path.sep)) {
for (const dir of process.env.PATH.split(pathEnvSep)) {
const absPath: string = dir + path.sep + command;
if (existsSync(absPath)) {
return absPath;