UNPKG

plaxtony

Version:

Static code analysis of SC2 Galaxy Script

58 lines 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReferencesProvider = void 0; const provider_1 = require("./provider"); const utils_1 = require("../compiler/utils"); const utils_2 = require("./utils"); const checker_1 = require("../compiler/checker"); ; class ReferencesProvider extends provider_1.AbstractProvider { constructor() { super(); this.locations = []; this.config = { currentWorkspaceOnly: false, }; } collectReferences(sourceFile, child) { if (child.kind === 113 /* Identifier */ && this.checker.getSymbolAtLocation(child) === this.searchSymbol) { this.locations.push({ uri: sourceFile.fileName, range: { start: utils_2.getLineAndCharacterOfPosition(sourceFile, child.pos), end: utils_2.getLineAndCharacterOfPosition(sourceFile, child.end), } }); } utils_1.forEachChild(child, (node) => { this.collectReferences(sourceFile, node); }); } onReferences(params, currentWorkspaceOnly) { this.locations = []; const sourceFile = this.store.documents.get(params.textDocument.uri); if (!sourceFile) return; const position = utils_2.getPositionOfLineAndCharacter(sourceFile, params.position.line, params.position.character); const currentToken = utils_2.getAdjacentIdentfier(position, sourceFile); if (!currentToken) { return null; } this.checker = new checker_1.TypeChecker(this.store); this.searchSymbol = this.checker.getSymbolAtLocation(currentToken); if (!this.searchSymbol) { return null; } for (const sourceFile of this.store.documents.values()) { if ((this.config.currentWorkspaceOnly || currentWorkspaceOnly === true) && !this.store.isUriInWorkspace(sourceFile.fileName) && !this.store.openDocuments.has(sourceFile.fileName)) { continue; } this.collectReferences(sourceFile, sourceFile); } return this.locations; } } exports.ReferencesProvider = ReferencesProvider; //# sourceMappingURL=references.js.map