-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
import { DocumentFilter, languages, workspace, TextDocumentChangeEvent, Disposable, Event, TextDocument } from 'vscode' | ||
import { EBNFRenameProvider } from './providers/RenameProvider' | ||
import { DocumentFilter, languages, workspace, TextDocumentChangeEvent, ExtensionContext, TextDocument } from 'vscode'; | ||
import { EBNFRenameProvider } from './providers/RenameProvider'; | ||
import { EBNFDefinitionProvider } from './providers/DefinitionProvider'; | ||
import { EBNFReferenceProvider } from './providers/EBNFReferenceProvider'; | ||
|
||
const EbnfSelector: DocumentFilter = { language: 'ebnf', scheme: 'file' }; | ||
export function activate(ctx: ExtensionContext): void | ||
{ | ||
const EbnfSelector: DocumentFilter = { language: 'ebnf', scheme: 'file' }; | ||
|
||
languages.registerRenameProvider(EbnfSelector, new EBNFRenameProvider()); | ||
languages.registerDefinitionProvider(EbnfSelector, new EBNFDefinitionProvider()); | ||
ctx.subscriptions.push(languages.registerRenameProvider(EbnfSelector, new EBNFRenameProvider())); | ||
ctx.subscriptions.push(languages.registerDefinitionProvider(EbnfSelector, new EBNFDefinitionProvider())); | ||
ctx.subscriptions.push(languages.registerReferenceProvider(EbnfSelector, new EBNFReferenceProvider())); | ||
|
||
workspace.onDidOpenTextDocument(OnDocumentOpen); | ||
workspace.onDidChangeTextDocument(OnDocumentChange); | ||
workspace.onDidCloseTextDocument(OnDocumentClose); | ||
|
||
function OnDocumentOpen(document: TextDocument) { | ||
// TODO: Not implemented yet | ||
// if the file is ebnf | ||
// parse and cache AST | ||
// workspace.onDidOpenTextDocument(OnDocumentOpen); | ||
// workspace.onDidChangeTextDocument(OnDocumentChange); | ||
// workspace.onDidCloseTextDocument(OnDocumentClose); | ||
} | ||
|
||
function OnDocumentChange(event: TextDocumentChangeEvent) { | ||
// TODO: Not implemented yet | ||
// if changes and file is ebnf | ||
// re-parse | ||
} | ||
// function OnDocumentOpen(document: TextDocument) | ||
// { | ||
// // TODO: Not implemented yet | ||
// // if the file is ebnf | ||
// // parse and cache AST | ||
// } | ||
|
||
// function OnDocumentChange(event: TextDocumentChangeEvent) | ||
// { | ||
// // TODO: Not implemented yet | ||
// // if changes and file is ebnf | ||
// // re-parse | ||
// } | ||
|
||
function OnDocumentClose(document: TextDocument) { | ||
// TODO: Not implemented yet | ||
// if the file is ebnf | ||
// remove from cache | ||
} | ||
// function OnDocumentClose(document: TextDocument) | ||
// { | ||
// // TODO: Not implemented yet | ||
// // if the file is ebnf | ||
// // remove from cache | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as vscode from "vscode"; | ||
import { CharStreams, CommonTokenStream } from 'antlr4ts'; | ||
import { ParseTreeListener } from 'antlr4ts/tree/ParseTreeListener'; | ||
|
||
import { EBNFLexer } from '../parser/EBNFLexer'; | ||
import { EBNFParser } from '../parser/EBNFParser'; | ||
import { ISymbolInfo } from '../ISymbolInfo'; | ||
import { IdentifierListener } from '../listeners/IdentifierListener'; | ||
|
||
export class EBNFReferenceProvider implements vscode.ReferenceProvider | ||
{ | ||
public provideReferences(document: vscode.TextDocument, position: vscode.Position, context: vscode.ReferenceContext, token: vscode.CancellationToken): vscode.ProviderResult<vscode.Location[]> | ||
{ | ||
const range = document.getWordRangeAtPosition(position); | ||
const text = document.getText(range); | ||
|
||
if (!text) | ||
{ | ||
return; | ||
} | ||
|
||
const content = document.getText(); | ||
const inputStream = CharStreams.fromString(content); | ||
const lexer = new EBNFLexer(inputStream); | ||
const tokenStream = new CommonTokenStream(lexer); | ||
const parser = new EBNFParser(tokenStream); | ||
const listener = new IdentifierListener(); | ||
parser.addParseListener(listener as ParseTreeListener); | ||
|
||
parser.syntax(); | ||
|
||
var result: vscode.Location[] | ||
= listener.symbols.filter(symbol => symbol.text == text) | ||
.map(ref => new vscode.Location(document.uri, | ||
new vscode.Range( | ||
ref.line - 1, | ||
ref.charPositionInLine, | ||
ref.line - 1, | ||
ref.charPositionInLine + ref.text.length | ||
))); | ||
|
||
return result; | ||
} | ||
} |