mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
This reverts commit d15a3fcc98.
This commit is contained in:
@@ -6,19 +6,18 @@
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { CodeLensModel } from 'vs/editor/contrib/codelens/codelens';
|
||||
import { ICodeLensData } from 'vs/editor/contrib/codelens/codelens';
|
||||
import { LRUCache, values } from 'vs/base/common/map';
|
||||
import { CodeLensProvider, CodeLensList, CodeLens } from 'vs/editor/common/modes';
|
||||
import { ICodeLensSymbol, CodeLensProvider } from 'vs/editor/common/modes';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { runWhenIdle } from 'vs/base/common/async';
|
||||
|
||||
export const ICodeLensCache = createDecorator<ICodeLensCache>('ICodeLensCache');
|
||||
|
||||
export interface ICodeLensCache {
|
||||
_serviceBrand: any;
|
||||
put(model: ITextModel, data: CodeLensModel): void;
|
||||
get(model: ITextModel): CodeLensModel | undefined;
|
||||
put(model: ITextModel, data: ICodeLensData[]): void;
|
||||
get(model: ITextModel): ICodeLensData[] | undefined;
|
||||
delete(model: ITextModel): void;
|
||||
}
|
||||
|
||||
@@ -31,7 +30,7 @@ class CacheItem {
|
||||
|
||||
constructor(
|
||||
readonly lineCount: number,
|
||||
readonly data: CodeLensModel
|
||||
readonly data: ICodeLensData[]
|
||||
) { }
|
||||
}
|
||||
|
||||
@@ -40,7 +39,7 @@ export class CodeLensCache implements ICodeLensCache {
|
||||
_serviceBrand: any;
|
||||
|
||||
private readonly _fakeProvider = new class implements CodeLensProvider {
|
||||
provideCodeLenses(): CodeLensList {
|
||||
provideCodeLenses(): ICodeLensSymbol[] {
|
||||
throw new Error('not supported');
|
||||
}
|
||||
};
|
||||
@@ -49,12 +48,9 @@ export class CodeLensCache implements ICodeLensCache {
|
||||
|
||||
constructor(@IStorageService storageService: IStorageService) {
|
||||
|
||||
// remove old data
|
||||
const oldkey = 'codelens/cache';
|
||||
runWhenIdle(() => storageService.remove(oldkey, StorageScope.WORKSPACE));
|
||||
const key = 'codelens/cache';
|
||||
|
||||
// restore lens data on start
|
||||
const key = 'codelens/cache2';
|
||||
const raw = storageService.get(key, StorageScope.WORKSPACE, '{}');
|
||||
this._deserialize(raw);
|
||||
|
||||
@@ -65,12 +61,13 @@ export class CodeLensCache implements ICodeLensCache {
|
||||
});
|
||||
}
|
||||
|
||||
put(model: ITextModel, data: CodeLensModel): void {
|
||||
|
||||
const lensModel = new CodeLensModel();
|
||||
lensModel.add({ lenses: data.lenses.map(v => v.symbol), dispose() { } }, this._fakeProvider);
|
||||
|
||||
const item = new CacheItem(model.getLineCount(), lensModel);
|
||||
put(model: ITextModel, data: ICodeLensData[]): void {
|
||||
const item = new CacheItem(model.getLineCount(), data.map(item => {
|
||||
return {
|
||||
symbol: item.symbol,
|
||||
provider: this._fakeProvider
|
||||
};
|
||||
}));
|
||||
this._cache.set(model.uri.toString(), item);
|
||||
}
|
||||
|
||||
@@ -89,7 +86,7 @@ export class CodeLensCache implements ICodeLensCache {
|
||||
const data: Record<string, ISerializedCacheData> = Object.create(null);
|
||||
this._cache.forEach((value, key) => {
|
||||
const lines = new Set<number>();
|
||||
for (const d of value.data.lenses) {
|
||||
for (const d of value.data) {
|
||||
lines.add(d.symbol.range.startLineNumber);
|
||||
}
|
||||
data[key] = {
|
||||
@@ -105,14 +102,14 @@ export class CodeLensCache implements ICodeLensCache {
|
||||
const data: Record<string, ISerializedCacheData> = JSON.parse(raw);
|
||||
for (const key in data) {
|
||||
const element = data[key];
|
||||
const lenses: CodeLens[] = [];
|
||||
const symbols: ICodeLensData[] = [];
|
||||
for (const line of element.lines) {
|
||||
lenses.push({ range: new Range(line, 1, line, 11) });
|
||||
symbols.push({
|
||||
provider: this._fakeProvider,
|
||||
symbol: { range: new Range(line, 1, line, 11) }
|
||||
});
|
||||
}
|
||||
|
||||
const model = new CodeLensModel();
|
||||
model.add({ lenses, dispose() { } }, this._fakeProvider);
|
||||
this._cache.set(key, new CacheItem(element.lineCount, model));
|
||||
this._cache.set(key, new CacheItem(element.lineCount, symbols));
|
||||
}
|
||||
} catch {
|
||||
// ignore...
|
||||
|
||||
Reference in New Issue
Block a user