Skip to content

Commit

Permalink
Fixes #3909: Revive javascript.validate.enable setting
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaeumer committed Mar 10, 2016
1 parent 310dd2d commit f87a633
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
5 changes: 5 additions & 0 deletions extensions/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
"default": null,
"description": "%typescript.tsdk.desc%"
},
"typescript.validate.enable": {
"type": "boolean",
"default": true,
"description": "%typescript.validate.enable%"
},
"javascript.validate.enable": {
"type": "boolean",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions extensions/typescript/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"configuration.typescript": "TypeScript configuration",
"typescript.useCodeSnippetsOnMethodSuggest.dec": "Complete functions with their parameter signature.",
"typescript.tsdk.desc": "Specifies the folder path containing the tsserver and lib*.d.ts files to use.",
"typescript.validate.enable": "Enable / disable TypeScript validation",
"javascript.validate.enable": "Enable / disable JavaScript validation"
}
21 changes: 20 additions & 1 deletion extensions/typescript/src/features/bufferSyncSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ export default class BufferSyncSupport {

private client: ITypescriptServiceClient;

private _validate: boolean;
private modeIds: Map<boolean>;
private disposables: Disposable[] = [];
private syncedBuffers: { [key: string]: SyncedBuffer };

private pendingDiagnostics: { [key: string]: number; };
private diagnosticDelayer: Delayer<any>;

constructor(client: ITypescriptServiceClient, modeIds: string[]) {
constructor(client: ITypescriptServiceClient, modeIds: string[], validate: boolean = true) {
this.client = client;
this.modeIds = Object.create(null);
modeIds.forEach(modeId => this.modeIds[modeId] = true);
this._validate = validate;

this.pendingDiagnostics = Object.create(null);
this.diagnosticDelayer = new Delayer<any>(100);
Expand All @@ -93,6 +95,14 @@ export default class BufferSyncSupport {
workspace.textDocuments.forEach(this.onDidAddDocument, this);
}

public get validate(): boolean {
return this._validate;
}

public set validate(value: boolean) {
this._validate = value;
}

public handles(file: string): boolean {
return !!this.syncedBuffers[file];
}
Expand Down Expand Up @@ -153,20 +163,29 @@ export default class BufferSyncSupport {
}

public requestAllDiagnostics() {
if (!this._validate) {
return;
}
Object.keys(this.syncedBuffers).forEach(filePath => this.pendingDiagnostics[filePath] = Date.now());
this.diagnosticDelayer.trigger(() => {
this.sendPendingDiagnostics();
});
}

public requestDiagnostic(file: string): void {
if (!this._validate) {
return;
}
this.pendingDiagnostics[file] = Date.now();
this.diagnosticDelayer.trigger(() => {
this.sendPendingDiagnostics();
});
}

private sendPendingDiagnostics(): void {
if (!this._validate) {
return;
}
let files = Object.keys(this.pendingDiagnostics).map((key) => {
return {
file: key,
Expand Down
25 changes: 20 additions & 5 deletions extensions/typescript/src/typescriptMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class LanguageManager {

constructor(client: TypeScriptServiceClient, description: LanguageDescription, validate: boolean = true) {
this.description = description;
this.bufferSyncSupport = new BufferSyncSupport(client, description.modeIds);
this.bufferSyncSupport = new BufferSyncSupport(client, description.modeIds, validate);
this.syntaxDiagnostics = Object.create(null);
this.currentDiagnostics = languages.createDiagnosticCollection(description.id);
this._validate = validate;
Expand All @@ -183,12 +183,20 @@ class LanguageManager {
return this.bufferSyncSupport.handles(file);
}

public get id(): string {
return this.description.id;
}

public get validate(): boolean {
return this._validate;
}

public set validate(value: boolean) {
if (this._validate === value) {
return;
}
this._validate = value;
this.bufferSyncSupport.validate = value;
if (value) {
this.triggerAllDiagnostics();
} else {
Expand All @@ -206,9 +214,6 @@ class LanguageManager {
}

public triggerAllDiagnostics(): void {
if (!this._validate) {
return;
}
this.bufferSyncSupport.requestAllDiagnostics();
}

Expand All @@ -226,6 +231,7 @@ class LanguageManager {
}
}

const validateSetting = 'validate.enable';
class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
private client: TypeScriptServiceClient;
private languages: LanguageManager[];
Expand All @@ -250,10 +256,12 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
this.languages = [];
this.languagePerId = Object.create(null);
descriptions.forEach(description => {
let manager = new LanguageManager(this.client, description);
let config = workspace.getConfiguration(description.id);
let manager = new LanguageManager(this.client, description, config.get(validateSetting, true));
this.languages.push(manager);
this.languagePerId[description.id] = manager;
});
workspace.onDidChangeConfiguration(this.configurationChanged, this);
}

public get serviceClient(): TypeScriptServiceClient {
Expand All @@ -275,6 +283,13 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
return null;
}

private configurationChanged(): void {
this.languages.forEach(language => {
let config = workspace.getConfiguration(language.id);
language.validate = config.get(validateSetting, true);
});
}

private triggerAllDiagnostics() {
Object.keys(this.languagePerId).forEach(key => this.languagePerId[key].triggerAllDiagnostics());
}
Expand Down

0 comments on commit f87a633

Please sign in to comment.