1.0.0 初始版
This commit is contained in:
83
dist/providers/definitionProvider.js
vendored
Normal file
83
dist/providers/definitionProvider.js
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DefinitionProvider = void 0;
|
||||
const vscode = __importStar(require("vscode"));
|
||||
// 定义跳转提供者类
|
||||
class DefinitionProvider {
|
||||
constructor(cacheManager) {
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
// 提供符号定义位置
|
||||
async provideDefinition(document, position, token) {
|
||||
// 检查是否在注释中,如果在注释中则不提供定义跳转
|
||||
const line = document.lineAt(position.line);
|
||||
const commentIndex = line.text.indexOf('//');
|
||||
if (commentIndex >= 0 && position.character > commentIndex) {
|
||||
return undefined;
|
||||
}
|
||||
// 获取光标位置的单词范围
|
||||
const range = document.getWordRangeAtPosition(position);
|
||||
if (!range) {
|
||||
return undefined;
|
||||
}
|
||||
// 获取单词
|
||||
const word = document.getText(range);
|
||||
// 查找函数定义
|
||||
const functions = this.cacheManager.findFunctionsByName(word);
|
||||
if (functions.length > 0) {
|
||||
if (functions.length === 1) {
|
||||
// 单个函数定义
|
||||
const func = functions[0];
|
||||
const uri = vscode.Uri.parse(`squirrel:/${func.filePath}`);
|
||||
const position = new vscode.Position(func.lineNumber - 1, 0);
|
||||
return new vscode.Location(uri, position);
|
||||
}
|
||||
else {
|
||||
// 多个同名函数定义,返回所有位置
|
||||
const locations = [];
|
||||
functions.forEach(func => {
|
||||
const uri = vscode.Uri.parse(`squirrel:/${func.filePath}`);
|
||||
const position = new vscode.Position(func.lineNumber - 1, 0);
|
||||
locations.push(new vscode.Location(uri, position));
|
||||
});
|
||||
return locations;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
exports.DefinitionProvider = DefinitionProvider;
|
||||
//# sourceMappingURL=definitionProvider.js.map
|
||||
Reference in New Issue
Block a user