mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Move goToProjectConfig into commands
This commit is contained in:
@@ -8,6 +8,11 @@ import * as vscode from 'vscode';
|
||||
import { TypeScriptServiceClientHost } from './typescriptMain';
|
||||
import { Command } from './utils/commandManager';
|
||||
import { Lazy } from './utils/lazy';
|
||||
import { openOrCreateConfigFile, isImplicitProjectConfigFile } from './utils/tsconfig';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
|
||||
export class ReloadTypeScriptProjectsCommand implements Command {
|
||||
public readonly id = 'typescript.reloadProjects';
|
||||
@@ -79,7 +84,7 @@ export class TypeScriptGoToProjectConfigCommand implements Command {
|
||||
public execute() {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (editor) {
|
||||
this.lazyClientHost.value.goToProjectConfig(true, editor.document.uri);
|
||||
goToProjectConfig(this.lazyClientHost.value, true, editor.document.uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +99,89 @@ export class JavaScriptGoToProjectConfigCommand implements Command {
|
||||
public execute() {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (editor) {
|
||||
this.lazyClientHost.value.goToProjectConfig(false, editor.document.uri);
|
||||
goToProjectConfig(this.lazyClientHost.value, false, editor.document.uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function goToProjectConfig(
|
||||
clientHost: TypeScriptServiceClientHost,
|
||||
isTypeScriptProject: boolean,
|
||||
resource: vscode.Uri
|
||||
): Promise<void> {
|
||||
const client = clientHost.serviceClient;
|
||||
const rootPath = client.getWorkspaceRootForResource(resource);
|
||||
if (!rootPath) {
|
||||
vscode.window.showInformationMessage(
|
||||
localize(
|
||||
'typescript.projectConfigNoWorkspace',
|
||||
'Please open a folder in VS Code to use a TypeScript or JavaScript project'));
|
||||
return;
|
||||
}
|
||||
|
||||
const file = client.normalizePath(resource);
|
||||
// TSServer errors when 'projectInfo' is invoked on a non js/ts file
|
||||
if (!file || !clientHost.handles(file)) {
|
||||
vscode.window.showWarningMessage(
|
||||
localize(
|
||||
'typescript.projectConfigUnsupportedFile',
|
||||
'Could not determine TypeScript or JavaScript project. Unsupported file type'));
|
||||
return;
|
||||
}
|
||||
|
||||
let res: protocol.ProjectInfoResponse | undefined = undefined;
|
||||
try {
|
||||
res = await client.execute('projectInfo', { file, needFileNameList: false } as protocol.ProjectInfoRequestArgs);
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
if (!res || !res.body) {
|
||||
vscode.window.showWarningMessage(localize('typescript.projectConfigCouldNotGetInfo', 'Could not determine TypeScript or JavaScript project'));
|
||||
return;
|
||||
}
|
||||
|
||||
const { configFileName } = res.body;
|
||||
if (configFileName && !isImplicitProjectConfigFile(configFileName)) {
|
||||
const doc = await vscode.workspace.openTextDocument(configFileName);
|
||||
vscode.window.showTextDocument(doc, vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
enum ProjectConfigAction {
|
||||
None,
|
||||
CreateConfig,
|
||||
LearnMore
|
||||
}
|
||||
|
||||
interface ProjectConfigMessageItem extends vscode.MessageItem {
|
||||
id: ProjectConfigAction;
|
||||
}
|
||||
|
||||
const selected = await vscode.window.showInformationMessage<ProjectConfigMessageItem>(
|
||||
(isTypeScriptProject
|
||||
? localize('typescript.noTypeScriptProjectConfig', 'File is not part of a TypeScript project')
|
||||
: localize('typescript.noJavaScriptProjectConfig', 'File is not part of a JavaScript project')
|
||||
), {
|
||||
title: isTypeScriptProject
|
||||
? localize('typescript.configureTsconfigQuickPick', 'Configure tsconfig.json')
|
||||
: localize('typescript.configureJsconfigQuickPick', 'Configure jsconfig.json'),
|
||||
id: ProjectConfigAction.CreateConfig
|
||||
}, {
|
||||
title: localize('typescript.projectConfigLearnMore', 'Learn More'),
|
||||
id: ProjectConfigAction.LearnMore
|
||||
});
|
||||
|
||||
switch (selected && selected.id) {
|
||||
case ProjectConfigAction.CreateConfig:
|
||||
openOrCreateConfigFile(isTypeScriptProject, rootPath, client.configuration);
|
||||
return;
|
||||
|
||||
case ProjectConfigAction.LearnMore:
|
||||
if (isTypeScriptProject) {
|
||||
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://go.microsoft.com/fwlink/?linkid=841896'));
|
||||
} else {
|
||||
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://go.microsoft.com/fwlink/?linkid=759670'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,13 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
// This must be the first statement otherwise modules might got loaded with
|
||||
// the wrong locale.
|
||||
import * as nls from 'vscode-nls';
|
||||
nls.config({ locale: vscode.env.language });
|
||||
nls.loadMessageBundle();
|
||||
|
||||
import { CommandManager } from './utils/commandManager';
|
||||
import { TypeScriptServiceClientHost } from './typescriptMain';
|
||||
import * as commands from './commands';
|
||||
|
||||
@@ -8,14 +8,7 @@
|
||||
* https://github.com/Microsoft/TypeScript-Sublime-Plugin/blob/master/TypeScript%20Indent.tmPreferences
|
||||
* ------------------------------------------------------------------------------------------ */
|
||||
|
||||
import { env, languages, commands, workspace, window, Memento, Diagnostic, Range, Disposable, Uri, MessageItem, DiagnosticSeverity, TextDocument, DocumentFilter } from 'vscode';
|
||||
|
||||
// This must be the first statement otherwise modules might got loaded with
|
||||
// the wrong locale.
|
||||
import * as nls from 'vscode-nls';
|
||||
nls.config({ locale: env.language });
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { languages, workspace, Memento, Diagnostic, Range, Disposable, Uri, DiagnosticSeverity, TextDocument, DocumentFilter } from 'vscode';
|
||||
import { basename } from 'path';
|
||||
|
||||
import * as Proto from './protocol';
|
||||
@@ -29,7 +22,6 @@ import BufferSyncSupport from './features/bufferSyncSupport';
|
||||
import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus';
|
||||
import VersionStatus from './utils/versionStatus';
|
||||
import { TypeScriptServerPlugin } from './utils/plugins';
|
||||
import { openOrCreateConfigFile, isImplicitProjectConfigFile } from './utils/tsconfig';
|
||||
import { tsLocationToVsPosition } from './utils/convert';
|
||||
import FormattingConfigurationManager from './features/formattingConfigurationManager';
|
||||
import * as languageConfigurations from './utils/languageConfigurations';
|
||||
@@ -375,86 +367,6 @@ export class TypeScriptServiceClientHost implements ITypeScriptServiceClientHost
|
||||
return !!this.findLanguage(file);
|
||||
}
|
||||
|
||||
public async goToProjectConfig(
|
||||
isTypeScriptProject: boolean,
|
||||
resource: Uri
|
||||
): Promise<void> {
|
||||
const rootPath = this.client.getWorkspaceRootForResource(resource);
|
||||
if (!rootPath) {
|
||||
window.showInformationMessage(
|
||||
localize(
|
||||
'typescript.projectConfigNoWorkspace',
|
||||
'Please open a folder in VS Code to use a TypeScript or JavaScript project'));
|
||||
return;
|
||||
}
|
||||
|
||||
const file = this.client.normalizePath(resource);
|
||||
// TSServer errors when 'projectInfo' is invoked on a non js/ts file
|
||||
if (!file || !this.handles(file)) {
|
||||
window.showWarningMessage(
|
||||
localize(
|
||||
'typescript.projectConfigUnsupportedFile',
|
||||
'Could not determine TypeScript or JavaScript project. Unsupported file type'));
|
||||
return;
|
||||
}
|
||||
|
||||
let res: protocol.ProjectInfoResponse | undefined = undefined;
|
||||
try {
|
||||
res = await this.client.execute('projectInfo', { file, needFileNameList: false } as protocol.ProjectInfoRequestArgs);
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
if (!res || !res.body) {
|
||||
window.showWarningMessage(localize('typescript.projectConfigCouldNotGetInfo', 'Could not determine TypeScript or JavaScript project'));
|
||||
return;
|
||||
}
|
||||
|
||||
const { configFileName } = res.body;
|
||||
if (configFileName && !isImplicitProjectConfigFile(configFileName)) {
|
||||
const doc = await workspace.openTextDocument(configFileName);
|
||||
window.showTextDocument(doc, window.activeTextEditor ? window.activeTextEditor.viewColumn : undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
enum ProjectConfigAction {
|
||||
None,
|
||||
CreateConfig,
|
||||
LearnMore
|
||||
}
|
||||
|
||||
interface ProjectConfigMessageItem extends MessageItem {
|
||||
id: ProjectConfigAction;
|
||||
}
|
||||
|
||||
const selected = await window.showInformationMessage<ProjectConfigMessageItem>(
|
||||
(isTypeScriptProject
|
||||
? localize('typescript.noTypeScriptProjectConfig', 'File is not part of a TypeScript project')
|
||||
: localize('typescript.noJavaScriptProjectConfig', 'File is not part of a JavaScript project')
|
||||
), {
|
||||
title: isTypeScriptProject
|
||||
? localize('typescript.configureTsconfigQuickPick', 'Configure tsconfig.json')
|
||||
: localize('typescript.configureJsconfigQuickPick', 'Configure jsconfig.json'),
|
||||
id: ProjectConfigAction.CreateConfig
|
||||
}, {
|
||||
title: localize('typescript.projectConfigLearnMore', 'Learn More'),
|
||||
id: ProjectConfigAction.LearnMore
|
||||
});
|
||||
|
||||
switch (selected && selected.id) {
|
||||
case ProjectConfigAction.CreateConfig:
|
||||
openOrCreateConfigFile(isTypeScriptProject, rootPath, this.client.configuration);
|
||||
return;
|
||||
|
||||
case ProjectConfigAction.LearnMore:
|
||||
if (isTypeScriptProject) {
|
||||
commands.executeCommand('vscode.open', Uri.parse('https://go.microsoft.com/fwlink/?linkid=841896'));
|
||||
} else {
|
||||
commands.executeCommand('vscode.open', Uri.parse('https://go.microsoft.com/fwlink/?linkid=759670'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private configurationChanged(): void {
|
||||
const config = workspace.getConfiguration('typescript');
|
||||
this.reportStyleCheckAsWarnings = config.get('reportStyleChecksAsWarnings', true);
|
||||
|
||||
Reference in New Issue
Block a user