hover functionality final refactoring

This commit is contained in:
Olivier Guinart 2017-09-23 18:16:06 -07:00
parent 6ef863618e
commit 367dd43955
2 changed files with 25 additions and 22 deletions

View File

@ -1,27 +1,8 @@
import * as vscode from 'vscode';
import * as data from '../strings/resources.json';
import * as hover from './hover';
// this method is called when vs code is activated
export function activate(context: vscode.ExtensionContext) {
hover.initializeOpcodesRegex();
let activeEditor = vscode.window.activeTextEditor;
if (activeEditor) {
hover.triggerUpdateDecorations(activeEditor);
}
vscode.window.onDidChangeActiveTextEditor(editor => {
activeEditor = editor;
if (editor) {
hover.triggerUpdateDecorations(activeEditor);
}
}, null, context.subscriptions);
vscode.workspace.onDidChangeTextDocument(event => {
if (activeEditor && event.document === activeEditor.document) {
hover.triggerUpdateDecorations(activeEditor);
}
}, null, context.subscriptions);
hover.activate(context);
}

View File

@ -5,8 +5,30 @@ import * as data from '../strings/resources.json';
// this is just to enable hover.
const opcodesDecorationType = vscode.window.createTextEditorDecorationType({ });
export function activate(context: vscode.ExtensionContext)
{
initializeOpcodesRegex();
let activeEditor = vscode.window.activeTextEditor;
if (activeEditor) {
triggerUpdateDecorations(activeEditor);
}
vscode.window.onDidChangeActiveTextEditor(editor => {
activeEditor = editor;
if (editor) {
triggerUpdateDecorations(activeEditor);
}
}, null, context.subscriptions);
vscode.workspace.onDidChangeTextDocument(event => {
if (activeEditor && event.document === activeEditor.document) {
triggerUpdateDecorations(activeEditor);
}
}, null, context.subscriptions);
}
var _regExp: RegExp;
export function initializeOpcodesRegex() {
function initializeOpcodesRegex() {
let r : string = "\\b(";
for (var prop in data) {
if (prop != "--^") {
@ -20,7 +42,7 @@ export function initializeOpcodesRegex() {
let _activeEditor: vscode.TextEditor;
var _timeout = null;
export function triggerUpdateDecorations(activeEditor: vscode.TextEditor) : NodeJS.Timer {
function triggerUpdateDecorations(activeEditor: vscode.TextEditor) : NodeJS.Timer {
_activeEditor = activeEditor;
if (_timeout) {
clearTimeout(_timeout);