Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Add document and workspace symbol provider #107

Merged
merged 8 commits into from
Jan 23, 2017
Prev Previous commit
Next Next commit
Parse file ahead when document symbol provider is used
  • Loading branch information
ypresto committed Dec 30, 2016
commit e3b253f11b62789886fdcff36146019178c9f29c
10 changes: 5 additions & 5 deletions locate/locate.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ module.exports = class Locate {
// add lookup hooks
}
listInFile(absPath) {
return _.clone(this.tree[absPath] || []);
const waitForParse = (absPath in this.tree) ? Promise.resolve() : this.parse(absPath);
return waitForParse.then(() => _.clone(this.tree[absPath] || []));
}
find(name) {
// because our word pattern is designed to match symbols
Expand All @@ -64,11 +65,9 @@ module.exports = class Locate {
const relPath = path.relative(this.root, absPath);
if (this.settings.exclude && minimatch(relPath, this.settings.exclude)) return;
if (this.settings.include && !minimatch(relPath, this.settings.include)) return;
this.rm(absPath);
locator(absPath)
return locator(absPath)
.then(result => {
if (!result) return;
this.tree[absPath] = flatten(result, absPath);
this.tree[absPath] = result ? flatten(result, absPath) : [];
}, err => {
if (err.code === 'EMFILE') {
// if there are too many open files
Expand All @@ -77,6 +76,7 @@ module.exports = class Locate {
} else {
// otherwise, report it
console.log(err);
this.rm(absPath);
}
});
}
Expand Down
15 changes: 8 additions & 7 deletions ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ function activate(context) {
};
const docSymbolProvider = {
provideDocumentSymbols: (document, token) => {
return locate.listInFile(document.fileName).map(match => {
const symbolKind = (symbolKindTable[match.type] || defaultSymbolKind)(match);
const parentName = match.parent ? match.parent.fullName : '';
const uri = vscode.Uri.file(match.file);
const location = new Location(uri, new Position(match.line, match.char));
return new SymbolInformation(match.name, symbolKind, parentName, location);
})
return locate.listInFile(document.fileName)
.then(matches => matches.map(match => {
const symbolKind = (symbolKindTable[match.type] || defaultSymbolKind)(match);
const parentName = match.parent ? match.parent.fullName : '';
const uri = vscode.Uri.file(match.file);
const location = new Location(uri, new Position(match.line, match.char));
return new SymbolInformation(match.name, symbolKind, parentName, location);
}));
}
};
subs.push(vscode.languages.registerDocumentSymbolProvider(['ruby', 'erb'], docSymbolProvider));
Expand Down