Go to defination: go to included module/file
This commit is contained in:
parent
9f1c592e70
commit
a49108bea3
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue