@elastic/ctags-langserver
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -82,87 +82,3 @@ "use strict"; | ||
const relativePath = path.relative(rootPath, filePath); | ||
const stream = ctags.createReadStream(path.resolve(rootPath, this.tagFileName)); | ||
return new Promise(resolve => { | ||
let results = []; | ||
// @ts-ignore | ||
stream.on('data', (tags) => { | ||
// @ts-ignore | ||
const definitions = tags.filter(tag => path.normalize(tag.file) === path.normalize(relativePath)); | ||
for (let def of definitions) { | ||
let symbolInformation = vscode_languageserver_protocol_1.SymbolInformation.create(def.name, vscode_languageserver_protocol_1.SymbolKind.Method, vscode_languageserver_protocol_1.Range.create(vscode_languageserver_protocol_1.Position.create(def.lineNumber - 1, 0), vscode_languageserver_protocol_1.Position.create(def.lineNumber - 1, 0)), params.textDocument.uri, relativePath); | ||
if (def.fields !== undefined) { | ||
if (def.fields.struct) { | ||
symbolInformation.containerName = def.fields.struct; | ||
} | ||
else if (def.fields.class) { | ||
symbolInformation.containerName = def.fields.class; | ||
} | ||
else if (def.fields.interface) { | ||
symbolInformation.containerName = def.fields.interface; | ||
} | ||
else if (def.fields.function) { | ||
symbolInformation.containerName = def.fields.function; | ||
} | ||
else if (def.fields.enum) { | ||
symbolInformation.containerName = def.fields.enum; | ||
} | ||
else if (def.fields.namespace) { | ||
symbolInformation.containerName = def.fields.namespace; | ||
} | ||
else if (def.fields.module) { | ||
symbolInformation.containerName = def.fields.module; | ||
} | ||
} | ||
switch (def.kind) { | ||
case 'namespace': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Namespace; | ||
break; | ||
case 'package': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Package; | ||
break; | ||
case 'module': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Module; | ||
break; | ||
case 'variable': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Variable; | ||
break; | ||
case 'function': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Function; | ||
break; | ||
case 'class': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Class; | ||
break; | ||
case 'field': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Field; | ||
break; | ||
case 'method': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Method; | ||
break; | ||
case 'struct': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Struct; | ||
break; | ||
case 'enum': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Enum; | ||
break; | ||
case 'enumerator': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.EnumMember; | ||
break; | ||
case 'member': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Field; | ||
break; | ||
case 'typedef': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Interface; | ||
break; | ||
case 'macro': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Constant; | ||
break; | ||
default: | ||
break; | ||
} | ||
results.push(symbolInformation); | ||
} | ||
}); | ||
stream.on('end', () => { | ||
resolve(results); | ||
}); | ||
}); | ||
return this.collectChildren(params.textDocument.uri).then(children => utils_1.toHierarchicalDocumentSymbol(children, relativePath)); | ||
}); | ||
@@ -173,3 +89,3 @@ } | ||
this.logger.log('full', params); | ||
const symbols = yield this.documentSymbol({ textDocument: params.textDocument }); | ||
const symbols = yield this.collectChildren(params.textDocument.uri); | ||
const detailSymbols = symbols.map(symbol => ({ | ||
@@ -286,2 +202,97 @@ symbolInformation: symbol, | ||
} | ||
collectChildren(unitURI) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const filePath = url_1.fileURLToPath(unitURI); | ||
const rootPath = this.findBelongedRootPath(filePath); | ||
if (!rootPath) { | ||
return []; | ||
} | ||
const relativePath = path.relative(rootPath, filePath); | ||
const stream = ctags.createReadStream(path.resolve(rootPath, this.tagFileName)); | ||
return new Promise(resolve => { | ||
let results = []; | ||
// @ts-ignore | ||
stream.on('data', (tags) => { | ||
// @ts-ignore | ||
const definitions = tags.filter(tag => path.normalize(tag.file) === path.normalize(relativePath)); | ||
for (let def of definitions) { | ||
let symbolInformation = vscode_languageserver_protocol_1.SymbolInformation.create(def.name, vscode_languageserver_protocol_1.SymbolKind.Method, vscode_languageserver_protocol_1.Range.create(vscode_languageserver_protocol_1.Position.create(def.lineNumber - 1, 0), vscode_languageserver_protocol_1.Position.create(def.lineNumber - 1, 0)), unitURI, relativePath); | ||
if (def.fields !== undefined) { | ||
if (def.fields.struct) { | ||
symbolInformation.containerName = def.fields.struct; | ||
} | ||
else if (def.fields.class) { | ||
symbolInformation.containerName = def.fields.class; | ||
} | ||
else if (def.fields.interface) { | ||
symbolInformation.containerName = def.fields.interface; | ||
} | ||
else if (def.fields.function) { | ||
symbolInformation.containerName = def.fields.function; | ||
} | ||
else if (def.fields.enum) { | ||
symbolInformation.containerName = def.fields.enum; | ||
} | ||
else if (def.fields.namespace) { | ||
symbolInformation.containerName = def.fields.namespace; | ||
} | ||
else if (def.fields.module) { | ||
symbolInformation.containerName = def.fields.module; | ||
} | ||
} | ||
switch (def.kind) { | ||
case 'namespace': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Namespace; | ||
break; | ||
case 'package': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Package; | ||
break; | ||
case 'module': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Module; | ||
break; | ||
case 'variable': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Variable; | ||
break; | ||
case 'function': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Function; | ||
break; | ||
case 'class': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Class; | ||
break; | ||
case 'field': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Field; | ||
break; | ||
case 'method': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Method; | ||
break; | ||
case 'struct': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Struct; | ||
break; | ||
case 'enum': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Enum; | ||
break; | ||
case 'enumerator': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.EnumMember; | ||
break; | ||
case 'member': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Field; | ||
break; | ||
case 'typedef': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Interface; | ||
break; | ||
case 'macro': | ||
symbolInformation.kind = vscode_languageserver_protocol_1.SymbolKind.Constant; | ||
break; | ||
default: | ||
break; | ||
} | ||
results.push(symbolInformation); | ||
} | ||
}); | ||
stream.on('end', () => { | ||
resolve(results); | ||
}); | ||
}); | ||
}); | ||
} | ||
findClosestTag(tags, fileName, line) { | ||
@@ -288,0 +299,0 @@ // Priority for shoosing tags (high to low): |
@@ -21,2 +21,3 @@ "use strict"; | ||
const path = __importStar(require("path")); | ||
const os = __importStar(require("os")); | ||
const url_1 = require("url"); | ||
@@ -40,3 +41,3 @@ const lsp_server_1 = require("./lsp-server"); | ||
beforeAll(() => __awaiter(this, void 0, void 0, function* () { | ||
rootPath = fs.mkdtempSync('/tmp/ctags-langserver'); | ||
rootPath = fs.mkdtempSync(path.resolve(os.tmpdir(), 'ctags-langserver')); | ||
sourceFilePath = path.resolve(rootPath, 'test.c'); | ||
@@ -57,3 +58,3 @@ sourceFileUrl = url_1.pathToFileURL(sourceFilePath).toString(); | ||
test('test didChangeWorkspaceFolders', () => { | ||
const addedRootPath = fs.mkdtempSync('/tmp/ctags-langserver'); | ||
const addedRootPath = fs.mkdtempSync(path.resolve(os.tmpdir(), 'ctags-langserver')); | ||
const addedSourceFilePath = path.resolve(addedRootPath, 'test.c'); | ||
@@ -81,9 +82,11 @@ fs.writeFileSync(addedSourceFilePath, content); | ||
kind: vscode_languageserver_protocol_1.SymbolKind.Variable, | ||
location: vscode_languageserver_protocol_1.Location.create(sourceFileUrl, vscode_languageserver_protocol_1.Range.create(vscode_languageserver_protocol_1.Position.create(9, 0), vscode_languageserver_protocol_1.Position.create(9, 0))), | ||
containerName: 'test.c' | ||
range: vscode_languageserver_protocol_1.Range.create(vscode_languageserver_protocol_1.Position.create(9, 0), vscode_languageserver_protocol_1.Position.create(9, 0)), | ||
selectionRange: vscode_languageserver_protocol_1.Range.create(vscode_languageserver_protocol_1.Position.create(9, 0), vscode_languageserver_protocol_1.Position.create(9, 0)), | ||
children: [] | ||
}, { | ||
name: 'max', | ||
kind: vscode_languageserver_protocol_1.SymbolKind.Function, | ||
location: vscode_languageserver_protocol_1.Location.create(sourceFileUrl, vscode_languageserver_protocol_1.Range.create(vscode_languageserver_protocol_1.Position.create(0, 0), vscode_languageserver_protocol_1.Position.create(0, 0))), | ||
containerName: 'test.c' | ||
range: vscode_languageserver_protocol_1.Range.create(vscode_languageserver_protocol_1.Position.create(0, 0), vscode_languageserver_protocol_1.Position.create(0, 0)), | ||
selectionRange: vscode_languageserver_protocol_1.Range.create(vscode_languageserver_protocol_1.Position.create(0, 0), vscode_languageserver_protocol_1.Position.create(0, 0)), | ||
children: [] | ||
}]); | ||
@@ -90,0 +93,0 @@ })); |
@@ -130,2 +130,33 @@ "use strict"; | ||
exports.grep = grep; | ||
function toHierarchicalDocumentSymbol(flattenedSymbolInformation, sourceFile) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let map = new Map(); | ||
let roots = []; | ||
let tmpResult = []; | ||
let i = 0; | ||
flattenedSymbolInformation.forEach(symbol => { | ||
const documentSymbolwithParent = { | ||
name: symbol.containerName === sourceFile ? symbol.name : `${symbol.containerName}.${symbol.name}`, | ||
kind: symbol.kind, | ||
range: symbol.location.range, | ||
selectionRange: symbol.location.range, | ||
children: [], | ||
parent: symbol.containerName | ||
}; | ||
map.set(documentSymbolwithParent.name, i++); | ||
tmpResult.push(documentSymbolwithParent); | ||
}); | ||
tmpResult.forEach(symbol => { | ||
if (symbol.parent !== sourceFile) { | ||
tmpResult[map.get(symbol.parent)].children.push(symbol); | ||
} | ||
else { | ||
roots.push(symbol); | ||
} | ||
delete symbol.parent; | ||
}); | ||
return roots; | ||
}); | ||
} | ||
exports.toHierarchicalDocumentSymbol = toHierarchicalDocumentSymbol; | ||
//# sourceMappingURL=utils.js.map |
@@ -21,2 +21,3 @@ "use strict"; | ||
const path = __importStar(require("path")); | ||
const os = __importStar(require("os")); | ||
const content = "int max(int foo, int bar)\n" + | ||
@@ -56,3 +57,3 @@ "{\n" + | ||
test("test grep", () => __awaiter(this, void 0, void 0, function* () { | ||
const rootPath = fs.mkdtempSync('/tmp/ctags-langserver'); | ||
const rootPath = fs.mkdtempSync(path.resolve(os.tmpdir(), 'ctags-langserver')); | ||
const sourceFilePath = path.resolve(rootPath, 'test.c'); | ||
@@ -76,2 +77,17 @@ const dir1Path = path.resolve(rootPath, 'dir1'); | ||
})); | ||
const data = '[{"name":"API","kind":2,"location":{"uri":"","range":{"start":{"line":18,"character":0},"end":{"line":18,"character":0}}}' + | ||
',"containerName":"Elasticsearch"},{"name":"Elasticsearch","kind":2,"location":{"uri":"","range":{"start":{"line":17,"character":0},"end"' + | ||
':{"line":17,"character":0}}},"containerName":"elasticsearch-api/lib/elasticsearch/api/utils.rb"},{"name":"Utils","kind":2,"location":{"uri"' + | ||
':"","range":{"start":{"line":22,"character":0},"end":{"line":22,"character":0}}},"containerName":"Elasticsearch.API"},{"name":"__bulkify","kind":6,' + | ||
'"location":{"uri":"","range":{"start":{"line":99,"character":0},"end":{"line":99,"character":0}}},"containerName":"Elasticsearch.API.Utils"}]'; | ||
const expectedData = '[{"name":"Elasticsearch","kind":2,"range":{"start":{"line":17,"character":0},"end":{"line":17,"character":0}},"selectionRange":' + | ||
'{"start":{"line":17,"character":0},"end":{"line":17,"character":0}},"children":[{"name":"Elasticsearch.API","kind":2,"range":{"start":{"line":18,"character":' + | ||
'0},"end":{"line":18,"character":0}},"selectionRange":{"start":{"line":18,"character":0},"end":{"line":18,"character":0}},"children":[{"name":"Elasticsearch.API.' + | ||
'Utils","kind":2,"range":{"start":{"line":22,"character":0},"end":{"line":22,"character":0}},"selectionRange":{"start":{"line":22,"' + | ||
'character":0},"end":{"line":22,"character":0}},"children":[{"name":"Elasticsearch.API.Utils.__bulkify","kind":6,"range":{"start":{"line":99,"character":0},' + | ||
'"end":{"line":99,"character":0}},"selectionRange":{"start":{"line":99,"character":0},"end":{"line":99,"character":0}},"children":[]}]}]}]}]'; | ||
test("test toHierarchicalDocumentSymbol", () => __awaiter(this, void 0, void 0, function* () { | ||
const symbolInformation = JSON.parse(data); | ||
expect(JSON.stringify(yield utils_1.toHierarchicalDocumentSymbol(symbolInformation, "elasticsearch-api/lib/elasticsearch/api/utils.rb"))).toEqual(expectedData); | ||
})); | ||
//# sourceMappingURL=utils.test.js.map |
{ | ||
"name": "@elastic/ctags-langserver", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "An all-languages language server built on top of ctags", | ||
@@ -5,0 +5,0 @@ "author": "Elastic", |
# ctags-langserver | ||
[![Build Status](https://travis-ci.org/elastic/ctags-langserver.svg?branch=master)](https://travis-ci.org/elastic/ctags-langserver) | ||
[![Build Status](https://travis-ci.org/elastic/ctags-langserver.svg?branch=master)](https://travis-ci.org/elastic/ctags-langserver) [![Build Status](https://ci.appveyor.com/api/projects/status/github/elastic/ctags-langserver?branch=master&svg=true)]() | ||
@@ -5,0 +5,0 @@ # Supported Protocol features |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14998283
25
936