mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
Set checkjs when generating jsconfig if javascript.implicitProjectConfig.checkJS is set
Fixes #37011
This commit is contained in:
@@ -570,7 +570,7 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
|
||||
|
||||
switch (selected && selected.id) {
|
||||
case ProjectConfigAction.CreateConfig:
|
||||
openOrCreateConfigFile(isTypeScriptProject, rootPath);
|
||||
openOrCreateConfigFile(isTypeScriptProject, rootPath, this.client.configuration);
|
||||
return;
|
||||
|
||||
case ProjectConfigAction.LearnMore:
|
||||
|
||||
@@ -8,6 +8,7 @@ import { CancellationToken, Uri, Event } from 'vscode';
|
||||
import * as Proto from './protocol';
|
||||
import API from './utils/api';
|
||||
import { TypeScriptServerPlugin } from './utils/plugins';
|
||||
import { TypeScriptServiceConfiguration } from './utils/configuration';
|
||||
|
||||
export interface ITypescriptServiceClientHost {
|
||||
syntaxDiagnosticsReceived(event: Proto.DiagnosticEvent): void;
|
||||
@@ -37,6 +38,8 @@ export interface ITypescriptServiceClient {
|
||||
|
||||
plugins: TypeScriptServerPlugin[];
|
||||
|
||||
configuration: TypeScriptServiceConfiguration;
|
||||
|
||||
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: 'close', args: Proto.FileRequestArgs, expectedResult: boolean, token?: CancellationToken): Promise<any>;
|
||||
|
||||
@@ -124,7 +124,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
private pathSeparator: string;
|
||||
|
||||
private _onReady: { promise: Promise<void>; resolve: () => void; reject: () => void; };
|
||||
private configuration: TypeScriptServiceConfiguration;
|
||||
private _configuration: TypeScriptServiceConfiguration;
|
||||
private versionProvider: TypeScriptVersionProvider;
|
||||
private versionPicker: TypeScriptVersionPicker;
|
||||
|
||||
@@ -173,28 +173,28 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
|
||||
this.requestQueue = new RequestQueue();
|
||||
this.callbacks = new CallbackMap();
|
||||
this.configuration = TypeScriptServiceConfiguration.loadFromWorkspace();
|
||||
this.versionProvider = new TypeScriptVersionProvider(this.configuration);
|
||||
this._configuration = TypeScriptServiceConfiguration.loadFromWorkspace();
|
||||
this.versionProvider = new TypeScriptVersionProvider(this._configuration);
|
||||
this.versionPicker = new TypeScriptVersionPicker(this.versionProvider, this.workspaceState);
|
||||
|
||||
this._apiVersion = API.defaultVersion;
|
||||
this.tracer = new Tracer(this.logger);
|
||||
|
||||
workspace.onDidChangeConfiguration(() => {
|
||||
const oldConfiguration = this.configuration;
|
||||
this.configuration = TypeScriptServiceConfiguration.loadFromWorkspace();
|
||||
const oldConfiguration = this._configuration;
|
||||
this._configuration = TypeScriptServiceConfiguration.loadFromWorkspace();
|
||||
|
||||
this.versionProvider.updateConfiguration(this.configuration);
|
||||
this.versionProvider.updateConfiguration(this._configuration);
|
||||
this.tracer.updateConfiguration();
|
||||
|
||||
if (this.servicePromise) {
|
||||
if (this.configuration.checkJs !== oldConfiguration.checkJs
|
||||
|| this.configuration.experimentalDecorators !== oldConfiguration.experimentalDecorators
|
||||
if (this._configuration.checkJs !== oldConfiguration.checkJs
|
||||
|| 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();
|
||||
}
|
||||
}
|
||||
@@ -204,6 +204,10 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
this.startService();
|
||||
}
|
||||
|
||||
public get configuration() {
|
||||
return this._configuration;
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
if (this.servicePromise) {
|
||||
this.servicePromise.then(cp => {
|
||||
@@ -333,7 +337,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
args.push('--useSingleInferredProject');
|
||||
}
|
||||
|
||||
if (this.configuration.disableAutomaticTypeAcquisition) {
|
||||
if (this._configuration.disableAutomaticTypeAcquisition) {
|
||||
args.push('--disableAutomaticTypingAcquisition');
|
||||
}
|
||||
}
|
||||
@@ -346,7 +350,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
|
||||
if (this.apiVersion.has222Features()) {
|
||||
if (this.configuration.tsServerLogLevel !== TsServerLogLevel.Off) {
|
||||
if (this._configuration.tsServerLogLevel !== TsServerLogLevel.Off) {
|
||||
try {
|
||||
const logDir = fs.mkdtempSync(path.join(os.tmpdir(), `vscode-tsserver-log-`));
|
||||
this.tsServerLogFile = path.join(logDir, `tsserver.log`);
|
||||
@@ -356,7 +360,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
|
||||
if (this.tsServerLogFile) {
|
||||
args.push('--logVerbosity', TsServerLogLevel.toString(this.configuration.tsServerLogLevel));
|
||||
args.push('--logVerbosity', TsServerLogLevel.toString(this._configuration.tsServerLogLevel));
|
||||
args.push('--logFile', this.tsServerLogFile);
|
||||
}
|
||||
}
|
||||
@@ -372,13 +376,13 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
}
|
||||
|
||||
if (this.apiVersion.has234Features()) {
|
||||
if (this.configuration.npmLocation) {
|
||||
args.push('--npmLocation', `"${this.configuration.npmLocation}"`);
|
||||
if (this._configuration.npmLocation) {
|
||||
args.push('--npmLocation', `"${this._configuration.npmLocation}"`);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.apiVersion.has260Features()) {
|
||||
const tsLocale = getTsLocale(this.configuration);
|
||||
const tsLocale = getTsLocale(this._configuration);
|
||||
if (tsLocale) {
|
||||
args.push('--locale', tsLocale);
|
||||
}
|
||||
@@ -472,7 +476,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
.then(() => false);
|
||||
}
|
||||
|
||||
if (this.configuration.tsServerLogLevel === TsServerLogLevel.Off) {
|
||||
if (this._configuration.tsServerLogLevel === TsServerLogLevel.Off) {
|
||||
return window.showErrorMessage<MessageItem>(
|
||||
localize(
|
||||
'typescript.openTsServerLog.loggingNotEnabled',
|
||||
@@ -513,7 +517,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
|
||||
hostInfo: 'vscode'
|
||||
};
|
||||
this.execute('configure', configureOptions);
|
||||
this.setCompilerOptionsForInferredProjects(this.configuration);
|
||||
this.setCompilerOptionsForInferredProjects(this._configuration);
|
||||
if (resendModels) {
|
||||
this.host.populateService();
|
||||
}
|
||||
|
||||
@@ -152,7 +152,10 @@ function createLargeProjectMonitorFromTypeScript(item: ExcludeHintItem, client:
|
||||
});
|
||||
}
|
||||
|
||||
function onConfigureExcludesSelected(client: ITypescriptServiceClient, configFileName: string) {
|
||||
function onConfigureExcludesSelected(
|
||||
client: ITypescriptServiceClient,
|
||||
configFileName: string
|
||||
) {
|
||||
if (!isImplicitProjectConfigFile(configFileName)) {
|
||||
vscode.workspace.openTextDocument(configFileName)
|
||||
.then(vscode.window.showTextDocument);
|
||||
@@ -161,12 +164,17 @@ function onConfigureExcludesSelected(client: ITypescriptServiceClient, configFil
|
||||
if (root) {
|
||||
openOrCreateConfigFile(
|
||||
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 item = new ExcludeHintItem(client);
|
||||
|
||||
@@ -5,24 +5,38 @@
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import { TypeScriptServiceConfiguration } from './configuration';
|
||||
|
||||
export function isImplicitProjectConfigFile(configFileName: string) {
|
||||
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": {
|
||||
"target": "ES6"$0
|
||||
${compilerOptions.join(',\n\t\t')}$0
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/node_modules/*"
|
||||
]
|
||||
}`);
|
||||
}
|
||||
|
||||
export function openOrCreateConfigFile(
|
||||
isTypeScriptProject: boolean,
|
||||
rootPath: string
|
||||
rootPath: string,
|
||||
config: TypeScriptServiceConfiguration
|
||||
): Thenable<vscode.TextEditor | null> {
|
||||
const configFile = vscode.Uri.file(path.join(rootPath, isTypeScriptProject ? 'tsconfig.json' : 'jsconfig.json'));
|
||||
const col = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
|
||||
@@ -33,7 +47,7 @@ export function openOrCreateConfigFile(
|
||||
const doc = await vscode.workspace.openTextDocument(configFile.with({ scheme: 'untitled' }));
|
||||
const editor = await vscode.window.showTextDocument(doc, col);
|
||||
if (editor.document.getText().length === 0) {
|
||||
await editor.insertSnippet(emptyConfig);
|
||||
await editor.insertSnippet(getEmptyConfig(isTypeScriptProject, config));
|
||||
}
|
||||
return editor;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user