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

Commit

Permalink
Implement DocumentSymbolProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ypresto committed Dec 30, 2016
1 parent c58853f commit 2d0ee14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions locate/locate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function flatten(locateInfo, file, parentName) {
const symbolInfo = {
// TODO: parse names like 'ActiveRecord::Base'
name: name,
type: type,
file: file,
line: posn.line,
char: posn.char,
Expand All @@ -37,6 +38,9 @@ module.exports = class Locate {
// always: do this file now (if it's in the tree)
// add lookup hooks
}
listInFile(absPath) {
return _.clone(this.tree[absPath] || []);
}
find(name) {
// because our word pattern is designed to match symbols
// things like Gem::RequestSet may request a search for ':RequestSet'
Expand Down
21 changes: 20 additions & 1 deletion ruby.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
let vscode = require('vscode');
const vscode = require('vscode');
const { Location, Position, SymbolKind, SymbolInformation } = vscode;

let Locate = require('./locate/locate');
let cp = require('child_process');
Expand Down Expand Up @@ -177,6 +178,24 @@ function activate(context) {
}
};
subs.push(vscode.languages.registerDefinitionProvider(['ruby', 'erb'], defProvider));
const symbolKindTable = {
class: () => SymbolKind.Class,
module: () => SymbolKind.Module,
method: symbolInfo => symbolInfo.name === 'initialize' ? SymbolKind.Constructor : SymbolKind.Method,
classMethod: () => SymbolKind.Method,
};
const docSymbolProvider = {
provideDocumentSymbols: (document, token) => {
return locate.listInFile(document.fileName).map(match => {
const symbolKind = symbolKindTable[match.type](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));
}

subs.push(vscode.window.onDidChangeActiveTextEditor(balanceEvent));
Expand Down

0 comments on commit 2d0ee14

Please sign in to comment.