mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
Adopt useOneInferredProject
This commit is contained in:
@@ -11,6 +11,7 @@ import { workspace, TextDocument, TextDocumentChangeEvent, TextDocumentContentCh
|
||||
import * as Proto from '../protocol';
|
||||
import { ITypescriptServiceClient, APIVersion } from '../typescriptService';
|
||||
import { Delayer } from '../utils/async';
|
||||
import LinkedMap from './linkedMap';
|
||||
|
||||
interface IDiagnosticRequestor {
|
||||
requestDiagnostic(filepath: string): void;
|
||||
@@ -110,6 +111,7 @@ export default class BufferSyncSupport {
|
||||
|
||||
private pendingDiagnostics: { [key: string]: number; };
|
||||
private diagnosticDelayer: Delayer<any>;
|
||||
private emitQueue: LinkedMap<string>;
|
||||
|
||||
constructor(client: ITypescriptServiceClient, modeIds: string[], diagnostics: Diagnostics, extensions: Map<boolean>, validate: boolean = true) {
|
||||
this.client = client;
|
||||
@@ -125,12 +127,14 @@ export default class BufferSyncSupport {
|
||||
this.diagnosticDelayer = new Delayer<any>(300);
|
||||
|
||||
this.syncedBuffers = Object.create(null);
|
||||
this.emitQueue = new LinkedMap<string>();
|
||||
}
|
||||
|
||||
public listen(): void {
|
||||
workspace.onDidOpenTextDocument(this.onDidOpenTextDocument, this, this.disposables);
|
||||
workspace.onDidCloseTextDocument(this.onDidCloseTextDocument, this, this.disposables);
|
||||
workspace.onDidChangeTextDocument(this.onDidChangeTextDocument, this, this.disposables);
|
||||
workspace.onDidSaveTextDocument(this.onDidSaveTextDocument, this, this.disposables);
|
||||
workspace.textDocuments.forEach(this.onDidOpenTextDocument, this);
|
||||
}
|
||||
|
||||
@@ -205,6 +209,17 @@ export default class BufferSyncSupport {
|
||||
syncedBuffer.onContentChanged(e.contentChanges);
|
||||
}
|
||||
|
||||
private onDidSaveTextDocument(document: TextDocument): void {
|
||||
let filepath: string = this.client.asAbsolutePath(document.uri);
|
||||
if (!filepath) {
|
||||
return;
|
||||
}
|
||||
let syncedBuffer = this.syncedBuffers[filepath];
|
||||
if (!syncedBuffer) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public requestAllDiagnostics() {
|
||||
if (!this._validate) {
|
||||
return;
|
||||
|
||||
153
extensions/typescript/src/features/linkedMap.ts
Normal file
153
extensions/typescript/src/features/linkedMap.ts
Normal file
@@ -0,0 +1,153 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
interface Item<T> {
|
||||
previous: Item<T>;
|
||||
next: Item<T>;
|
||||
key: string;
|
||||
value: T;
|
||||
}
|
||||
|
||||
export default class LinkedMap<T> {
|
||||
|
||||
private map: Map<Item<T>>;
|
||||
private head: Item<T>;
|
||||
private tail: Item<T>;
|
||||
private _length: number;
|
||||
|
||||
constructor() {
|
||||
this.map = Object.create(null);
|
||||
this.head = undefined;
|
||||
this.tail = undefined;
|
||||
this._length = 0;
|
||||
}
|
||||
|
||||
public isEmpty(): boolean {
|
||||
return !this.head && !this.tail;
|
||||
}
|
||||
|
||||
public length(): number {
|
||||
return this._length;
|
||||
}
|
||||
|
||||
public get(key: string): T {
|
||||
const item = this.map[key];
|
||||
if (!item) {
|
||||
return undefined;
|
||||
}
|
||||
return item.value;
|
||||
}
|
||||
|
||||
public add(key: string, value: T, touch = false): void {
|
||||
let item = this.map[key];
|
||||
if (item) {
|
||||
item.value = value;
|
||||
if (touch) {
|
||||
this.touch(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
item = { key, value, next: undefined, previous: undefined };
|
||||
if (touch) {
|
||||
this.addItemFirst(item);
|
||||
}
|
||||
else {
|
||||
this.addItemLast(item);
|
||||
}
|
||||
this.map[key] = item;
|
||||
this._length++;
|
||||
}
|
||||
}
|
||||
|
||||
public remove(key: string): T {
|
||||
const item = this.map[key];
|
||||
if (!item) {
|
||||
return undefined;
|
||||
}
|
||||
delete this.map[key];
|
||||
this.removeItem(item);
|
||||
this._length--;
|
||||
return item.value;
|
||||
}
|
||||
|
||||
public shift(): T {
|
||||
if (!this.head && !this.tail) {
|
||||
return undefined;
|
||||
}
|
||||
const item = this.head;
|
||||
delete this.map[item.key];
|
||||
this.removeItem(item);
|
||||
this._length--;
|
||||
return item.value;
|
||||
}
|
||||
|
||||
private addItemFirst(item: Item<T>): void {
|
||||
// First time Insert
|
||||
if (!this.head && !this.tail) {
|
||||
this.tail = item;
|
||||
}
|
||||
else {
|
||||
item.next = this.head;
|
||||
this.head.previous = item;
|
||||
}
|
||||
this.head = item;
|
||||
}
|
||||
|
||||
private addItemLast(item: Item<T>): void {
|
||||
// First time Insert
|
||||
if (!this.head && !this.tail) {
|
||||
this.head = item;
|
||||
}
|
||||
else {
|
||||
item.previous = this.tail;
|
||||
this.tail.next = item;
|
||||
}
|
||||
this.tail = item;
|
||||
}
|
||||
|
||||
private removeItem(item: Item<T>): void {
|
||||
if (item === this.head && item === this.tail) {
|
||||
this.head = undefined;
|
||||
this.tail = undefined;
|
||||
}
|
||||
else if (item === this.head) {
|
||||
this.head = item.next;
|
||||
}
|
||||
else if (item === this.tail) {
|
||||
this.tail = item.previous;
|
||||
}
|
||||
else {
|
||||
const next = item.next;
|
||||
const previous = item.previous;
|
||||
next.previous = previous;
|
||||
previous.next = next;
|
||||
}
|
||||
}
|
||||
|
||||
private touch(item: Item<T>): void {
|
||||
if (item === this.head) {
|
||||
return;
|
||||
}
|
||||
|
||||
const next = item.next;
|
||||
const previous = item.previous;
|
||||
|
||||
// Unlink the item
|
||||
if (item === this.tail) {
|
||||
this.tail = previous;
|
||||
}
|
||||
else {
|
||||
// Both next and previous are not null since item was neither head nor tail.
|
||||
next.previous = previous;
|
||||
previous.next = next;
|
||||
}
|
||||
|
||||
// Insert the node at head
|
||||
item.previous = undefined;
|
||||
item.next = this.head;
|
||||
this.head.previous = item;
|
||||
this.head = item;
|
||||
}
|
||||
}
|
||||
1947
extensions/typescript/src/protocol.d.ts
vendored
1947
extensions/typescript/src/protocol.d.ts
vendored
File diff suppressed because it is too large
Load Diff
1947
extensions/typescript/src/protocol.ts
Normal file
1947
extensions/typescript/src/protocol.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -75,5 +75,8 @@ export interface ITypescriptServiceClient {
|
||||
execute(command: 'projectInfo', args: Proto.ProjectInfoRequestArgs, token?: CancellationToken): Promise<Proto.ProjectInfoResponse>;
|
||||
execute(command: 'reloadProjects', args: any, expectedResult: boolean, token?: CancellationToken): Promise<any>;
|
||||
execute(command: 'reload', args: Proto.ReloadRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise<any>;
|
||||
execute(command: 'compilerOptionsForInferredProjects', args: Proto.SetCompilerOptionsForInferredProjectsArgs, token?: CancellationToken): Promise<any>;
|
||||
execute(command: 'compileOnSaveAffectedFileList', args: Proto.CompileOnSaveEmitFileRequestArgs, token?: CancellationToken): Promise<Proto.CompileOnSaveAffectedFileListResponse>;
|
||||
execute(command: 'compileOnSaveEmitFile', args: Proto.CompileOnSaveEmitFileRequestArgs, token?: CancellationToken): Promise<any>;
|
||||
execute(command: string, args: any, expectedResult: boolean | CancellationToken, token?: CancellationToken): Promise<any>;
|
||||
}
|
||||
@@ -491,16 +491,30 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
|
||||
private serviceStarted(resendModels: boolean): void {
|
||||
let configureOptions: Proto.ConfigureRequestArguments = {
|
||||
hostInfo: 'vscode',
|
||||
useOneInferredProject: true
|
||||
};
|
||||
if (this._experimentalAutoBuild && this.storagePath) {
|
||||
try {
|
||||
fs.mkdirSync(this.storagePath);
|
||||
} catch (error) {
|
||||
}
|
||||
this.execute('configure', {
|
||||
autoBuild: true,
|
||||
metaDataDirectory: this.storagePath
|
||||
});
|
||||
configureOptions.autoDiagnostics = true;
|
||||
configureOptions.metaDataDirectory = this.storagePath;
|
||||
}
|
||||
this.execute('configure', configureOptions);
|
||||
let compilerOptions: Proto.ExternalProjectCompilerOptions = {
|
||||
module: Proto.ModuleKind.CommonJS,
|
||||
target: Proto.ScriptTarget.ES5,
|
||||
allowJs: true,
|
||||
allowSyntheticDefaultImports: true
|
||||
};
|
||||
let args: Proto.SetCompilerOptionsForInferredProjectsArgs = {
|
||||
options: compilerOptions
|
||||
};
|
||||
this.execute('compilerOptionsForInferredProjects', args);
|
||||
|
||||
if (resendModels) {
|
||||
this.host.populateService();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user