提交 abcdfe2c 编写于 作者: M Matt Bierner

Set checkjs when generating jsconfig if javascript.implicitProjectConfig.checkJS is set

Fixes #37011
上级 33aeb8e9
...@@ -570,7 +570,7 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost { ...@@ -570,7 +570,7 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
switch (selected && selected.id) { switch (selected && selected.id) {
case ProjectConfigAction.CreateConfig: case ProjectConfigAction.CreateConfig:
openOrCreateConfigFile(isTypeScriptProject, rootPath); openOrCreateConfigFile(isTypeScriptProject, rootPath, this.client.configuration);
return; return;
case ProjectConfigAction.LearnMore: case ProjectConfigAction.LearnMore:
......
...@@ -8,6 +8,7 @@ import { CancellationToken, Uri, Event } from 'vscode'; ...@@ -8,6 +8,7 @@ import { CancellationToken, Uri, Event } from 'vscode';
import * as Proto from './protocol'; import * as Proto from './protocol';
import API from './utils/api'; import API from './utils/api';
import { TypeScriptServerPlugin } from './utils/plugins'; import { TypeScriptServerPlugin } from './utils/plugins';
import { TypeScriptServiceConfiguration } from './utils/configuration';
export interface ITypescriptServiceClientHost { export interface ITypescriptServiceClientHost {
syntaxDiagnosticsReceived(event: Proto.DiagnosticEvent): void; syntaxDiagnosticsReceived(event: Proto.DiagnosticEvent): void;
...@@ -37,6 +38,8 @@ export interface ITypescriptServiceClient { ...@@ -37,6 +38,8 @@ export interface ITypescriptServiceClient {
plugins: TypeScriptServerPlugin[]; plugins: TypeScriptServerPlugin[];
configuration: TypeScriptServiceConfiguration;
execute(command: 'configure', args: Proto.ConfigureRequestArguments, token?: CancellationToken): Promise<Proto.ConfigureResponse>; execute(command: 'configure', args: Proto.ConfigureRequestArguments, token?: CancellationToken): Promise<Proto.ConfigureResponse>;
execute(command: 'open', args: Proto.OpenRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise<any>; execute(command: 'open', args: Proto.OpenRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise<any>;
execute(command: 'close', args: Proto.FileRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise<any>; execute(command: 'close', args: Proto.FileRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise<any>;
......
...@@ -124,7 +124,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -124,7 +124,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
private pathSeparator: string; private pathSeparator: string;
private _onReady: { promise: Promise<void>; resolve: () => void; reject: () => void; }; private _onReady: { promise: Promise<void>; resolve: () => void; reject: () => void; };
private configuration: TypeScriptServiceConfiguration; private _configuration: TypeScriptServiceConfiguration;
private versionProvider: TypeScriptVersionProvider; private versionProvider: TypeScriptVersionProvider;
private versionPicker: TypeScriptVersionPicker; private versionPicker: TypeScriptVersionPicker;
...@@ -173,28 +173,28 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -173,28 +173,28 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
this.requestQueue = new RequestQueue(); this.requestQueue = new RequestQueue();
this.callbacks = new CallbackMap(); this.callbacks = new CallbackMap();
this.configuration = TypeScriptServiceConfiguration.loadFromWorkspace(); this._configuration = TypeScriptServiceConfiguration.loadFromWorkspace();
this.versionProvider = new TypeScriptVersionProvider(this.configuration); this.versionProvider = new TypeScriptVersionProvider(this._configuration);
this.versionPicker = new TypeScriptVersionPicker(this.versionProvider, this.workspaceState); this.versionPicker = new TypeScriptVersionPicker(this.versionProvider, this.workspaceState);
this._apiVersion = API.defaultVersion; this._apiVersion = API.defaultVersion;
this.tracer = new Tracer(this.logger); this.tracer = new Tracer(this.logger);
workspace.onDidChangeConfiguration(() => { workspace.onDidChangeConfiguration(() => {
const oldConfiguration = this.configuration; const oldConfiguration = this._configuration;
this.configuration = TypeScriptServiceConfiguration.loadFromWorkspace(); this._configuration = TypeScriptServiceConfiguration.loadFromWorkspace();
this.versionProvider.updateConfiguration(this.configuration); this.versionProvider.updateConfiguration(this._configuration);
this.tracer.updateConfiguration(); this.tracer.updateConfiguration();
if (this.servicePromise) { if (this.servicePromise) {
if (this.configuration.checkJs !== oldConfiguration.checkJs if (this._configuration.checkJs !== oldConfiguration.checkJs
|| this.configuration.experimentalDecorators !== oldConfiguration.experimentalDecorators || this._configuration.experimentalDecorators !== oldConfiguration.experimentalDecorators
) { ) {
this.setCompilerOptionsForInferredProjects(this.configuration); this.setCompilerOptionsForInferredProjects(this._configuration);
} }
if (!this.configuration.isEqualTo(oldConfiguration)) { if (!this._configuration.isEqualTo(oldConfiguration)) {
this.restartTsServer(); this.restartTsServer();
} }
} }
...@@ -204,6 +204,10 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -204,6 +204,10 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
this.startService(); this.startService();
} }
public get configuration() {
return this._configuration;
}
public dispose() { public dispose() {
if (this.servicePromise) { if (this.servicePromise) {
this.servicePromise.then(cp => { this.servicePromise.then(cp => {
...@@ -333,7 +337,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -333,7 +337,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
args.push('--useSingleInferredProject'); args.push('--useSingleInferredProject');
} }
if (this.configuration.disableAutomaticTypeAcquisition) { if (this._configuration.disableAutomaticTypeAcquisition) {
args.push('--disableAutomaticTypingAcquisition'); args.push('--disableAutomaticTypingAcquisition');
} }
} }
...@@ -346,7 +350,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -346,7 +350,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
} }
if (this.apiVersion.has222Features()) { if (this.apiVersion.has222Features()) {
if (this.configuration.tsServerLogLevel !== TsServerLogLevel.Off) { if (this._configuration.tsServerLogLevel !== TsServerLogLevel.Off) {
try { try {
const logDir = fs.mkdtempSync(path.join(os.tmpdir(), `vscode-tsserver-log-`)); const logDir = fs.mkdtempSync(path.join(os.tmpdir(), `vscode-tsserver-log-`));
this.tsServerLogFile = path.join(logDir, `tsserver.log`); this.tsServerLogFile = path.join(logDir, `tsserver.log`);
...@@ -356,7 +360,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -356,7 +360,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
} }
if (this.tsServerLogFile) { if (this.tsServerLogFile) {
args.push('--logVerbosity', TsServerLogLevel.toString(this.configuration.tsServerLogLevel)); args.push('--logVerbosity', TsServerLogLevel.toString(this._configuration.tsServerLogLevel));
args.push('--logFile', this.tsServerLogFile); args.push('--logFile', this.tsServerLogFile);
} }
} }
...@@ -372,13 +376,13 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -372,13 +376,13 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
} }
if (this.apiVersion.has234Features()) { if (this.apiVersion.has234Features()) {
if (this.configuration.npmLocation) { if (this._configuration.npmLocation) {
args.push('--npmLocation', `"${this.configuration.npmLocation}"`); args.push('--npmLocation', `"${this._configuration.npmLocation}"`);
} }
} }
if (this.apiVersion.has260Features()) { if (this.apiVersion.has260Features()) {
const tsLocale = getTsLocale(this.configuration); const tsLocale = getTsLocale(this._configuration);
if (tsLocale) { if (tsLocale) {
args.push('--locale', tsLocale); args.push('--locale', tsLocale);
} }
...@@ -472,7 +476,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -472,7 +476,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
.then(() => false); .then(() => false);
} }
if (this.configuration.tsServerLogLevel === TsServerLogLevel.Off) { if (this._configuration.tsServerLogLevel === TsServerLogLevel.Off) {
return window.showErrorMessage<MessageItem>( return window.showErrorMessage<MessageItem>(
localize( localize(
'typescript.openTsServerLog.loggingNotEnabled', 'typescript.openTsServerLog.loggingNotEnabled',
...@@ -513,7 +517,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient ...@@ -513,7 +517,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
hostInfo: 'vscode' hostInfo: 'vscode'
}; };
this.execute('configure', configureOptions); this.execute('configure', configureOptions);
this.setCompilerOptionsForInferredProjects(this.configuration); this.setCompilerOptionsForInferredProjects(this._configuration);
if (resendModels) { if (resendModels) {
this.host.populateService(); this.host.populateService();
} }
......
...@@ -152,7 +152,10 @@ function createLargeProjectMonitorFromTypeScript(item: ExcludeHintItem, client: ...@@ -152,7 +152,10 @@ function createLargeProjectMonitorFromTypeScript(item: ExcludeHintItem, client:
}); });
} }
function onConfigureExcludesSelected(client: ITypescriptServiceClient, configFileName: string) { function onConfigureExcludesSelected(
client: ITypescriptServiceClient,
configFileName: string
) {
if (!isImplicitProjectConfigFile(configFileName)) { if (!isImplicitProjectConfigFile(configFileName)) {
vscode.workspace.openTextDocument(configFileName) vscode.workspace.openTextDocument(configFileName)
.then(vscode.window.showTextDocument); .then(vscode.window.showTextDocument);
...@@ -161,12 +164,17 @@ function onConfigureExcludesSelected(client: ITypescriptServiceClient, configFil ...@@ -161,12 +164,17 @@ function onConfigureExcludesSelected(client: ITypescriptServiceClient, configFil
if (root) { if (root) {
openOrCreateConfigFile( openOrCreateConfigFile(
configFileName.match(/tsconfig\.?.*\.json/) !== null, configFileName.match(/tsconfig\.?.*\.json/) !== null,
root); root,
client.configuration);
} }
} }
} }
export function create(client: ITypescriptServiceClient, isOpen: (path: string) => Promise<boolean>, memento: vscode.Memento) { export function create(
client: ITypescriptServiceClient,
isOpen: (path: string) => Promise<boolean>,
memento: vscode.Memento
) {
const toDispose: vscode.Disposable[] = []; const toDispose: vscode.Disposable[] = [];
const item = new ExcludeHintItem(client); const item = new ExcludeHintItem(client);
......
...@@ -5,24 +5,38 @@ ...@@ -5,24 +5,38 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as path from 'path'; import * as path from 'path';
import { TypeScriptServiceConfiguration } from './configuration';
export function isImplicitProjectConfigFile(configFileName: string) { export function isImplicitProjectConfigFile(configFileName: string) {
return configFileName.indexOf('/dev/null/') === 0; return configFileName.indexOf('/dev/null/') === 0;
} }
const emptyConfig = new vscode.SnippetString(`{ function getEmptyConfig(
isTypeScriptProject: boolean,
config: TypeScriptServiceConfiguration
) {
const compilerOptions = ['"target": "ES6"'];
if (!isTypeScriptProject && config.checkJs) {
compilerOptions.push('"checkJs": true');
}
if (!isTypeScriptProject && config.experimentalDecorators) {
compilerOptions.push('"experimentalDecorators": true');
}
return new vscode.SnippetString(`{
"compilerOptions": { "compilerOptions": {
"target": "ES6"$0 ${compilerOptions.join(',\n\t\t')}$0
}, },
"exclude": [ "exclude": [
"node_modules", "node_modules",
"**/node_modules/*" "**/node_modules/*"
] ]
}`); }`);
}
export function openOrCreateConfigFile( export function openOrCreateConfigFile(
isTypeScriptProject: boolean, isTypeScriptProject: boolean,
rootPath: string rootPath: string,
config: TypeScriptServiceConfiguration
): Thenable<vscode.TextEditor | null> { ): Thenable<vscode.TextEditor | null> {
const configFile = vscode.Uri.file(path.join(rootPath, isTypeScriptProject ? 'tsconfig.json' : 'jsconfig.json')); const configFile = vscode.Uri.file(path.join(rootPath, isTypeScriptProject ? 'tsconfig.json' : 'jsconfig.json'));
const col = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined; const col = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
...@@ -33,7 +47,7 @@ export function openOrCreateConfigFile( ...@@ -33,7 +47,7 @@ export function openOrCreateConfigFile(
const doc = await vscode.workspace.openTextDocument(configFile.with({ scheme: 'untitled' })); const doc = await vscode.workspace.openTextDocument(configFile.with({ scheme: 'untitled' }));
const editor = await vscode.window.showTextDocument(doc, col); const editor = await vscode.window.showTextDocument(doc, col);
if (editor.document.getText().length === 0) { if (editor.document.getText().length === 0) {
await editor.insertSnippet(emptyConfig); await editor.insertSnippet(getEmptyConfig(isTypeScriptProject, config));
} }
return editor; return editor;
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册