mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
cache the scripts for the hover
This commit is contained in:
parent
73b72464b3
commit
22f0337064
|
@ -8,8 +8,8 @@ import * as httpRequest from 'request-light';
|
|||
import * as vscode from 'vscode';
|
||||
import { addJSONProviders } from './features/jsonContributions';
|
||||
import { NpmScriptsTreeDataProvider } from './npmView';
|
||||
import { invalidateScriptsCache, NpmTaskProvider } from './tasks';
|
||||
import { NpmScriptHoverProvider } from './scriptHover';
|
||||
import { invalidateTasksCache, NpmTaskProvider } from './tasks';
|
||||
import { invalidateHoverScriptsCache, NpmScriptHoverProvider } from './scriptHover';
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<void> {
|
||||
const taskProvider = registerTaskProvider(context);
|
||||
|
@ -20,7 +20,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
|||
vscode.workspace.onDidChangeConfiguration((e) => {
|
||||
configureHttpRequest();
|
||||
if (e.affectsConfiguration('npm.exclude')) {
|
||||
invalidateScriptsCache();
|
||||
invalidateTasksCache();
|
||||
if (treeDataProvider) {
|
||||
treeDataProvider.refresh();
|
||||
}
|
||||
|
@ -35,11 +35,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
|||
}
|
||||
|
||||
function registerTaskProvider(context: vscode.ExtensionContext): vscode.Disposable | undefined {
|
||||
|
||||
function invalidateScriptCaches() {
|
||||
invalidateHoverScriptsCache();
|
||||
invalidateTasksCache();
|
||||
}
|
||||
|
||||
if (vscode.workspace.workspaceFolders) {
|
||||
let watcher = vscode.workspace.createFileSystemWatcher('**/package.json');
|
||||
watcher.onDidChange((_e) => invalidateScriptsCache());
|
||||
watcher.onDidDelete((_e) => invalidateScriptsCache());
|
||||
watcher.onDidCreate((_e) => invalidateScriptsCache());
|
||||
watcher.onDidChange((_e) => invalidateScriptCaches());
|
||||
watcher.onDidDelete((_e) => invalidateScriptCaches());
|
||||
watcher.onDidCreate((_e) => invalidateScriptCaches());
|
||||
context.subscriptions.push(watcher);
|
||||
|
||||
let provider: vscode.TaskProvider = new NpmTaskProvider(context);
|
||||
|
@ -74,7 +80,6 @@ function registerHoverProvider(context: vscode.ExtensionContext): NpmScriptHover
|
|||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
function configureHttpRequest() {
|
||||
const httpSettings = vscode.workspace.getConfiguration('http');
|
||||
httpRequest.configure(httpSettings.get<string>('proxy', ''), httpSettings.get<boolean>('proxyStrictSSL', true));
|
||||
|
|
|
@ -15,6 +15,13 @@ import * as nls from 'vscode-nls';
|
|||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
let cachedDocument: Uri | undefined = undefined;
|
||||
let cachedScriptsMap: Map<string, [number, number, string]> | undefined = undefined;
|
||||
|
||||
export function invalidateHoverScriptsCache() {
|
||||
cachedDocument = undefined;
|
||||
}
|
||||
|
||||
export class NpmScriptHoverProvider implements HoverProvider {
|
||||
private extensionContext: ExtensionContext;
|
||||
|
||||
|
@ -25,10 +32,14 @@ export class NpmScriptHoverProvider implements HoverProvider {
|
|||
}
|
||||
|
||||
public provideHover(document: TextDocument, position: Position, _token: CancellationToken): ProviderResult<Hover> {
|
||||
let result = findAllScriptRanges(document.getText());
|
||||
let hover: Hover | undefined = undefined;
|
||||
|
||||
result.forEach((value, key) => {
|
||||
if (!cachedDocument || cachedDocument.fsPath !== document.uri.fsPath) {
|
||||
cachedScriptsMap = findAllScriptRanges(document.getText());
|
||||
cachedDocument = document.uri;
|
||||
}
|
||||
|
||||
cachedScriptsMap!.forEach((value, key) => {
|
||||
let start = document.positionAt(value[0]);
|
||||
let end = document.positionAt(value[0] + value[1]);
|
||||
let range = new Range(start, end);
|
||||
|
|
|
@ -41,7 +41,7 @@ export class NpmTaskProvider implements TaskProvider {
|
|||
}
|
||||
}
|
||||
|
||||
export function invalidateScriptsCache() {
|
||||
export function invalidateTasksCache() {
|
||||
cachedTasks = undefined;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue