提交 8d6645c2 编写于 作者: M Matt Bierner

Initial work on making ts extension multiroot aware

上级 dd07cadd
......@@ -50,8 +50,11 @@ class SyncedBuffer {
}
}
if (workspace.rootPath && this.client.apiVersion.has230Features()) {
args.projectRootPath = workspace.rootPath;
if (this.client.apiVersion.has230Features()) {
const root = this.client.getWorkspaceRootForResource(this.document.uri);
if (root) {
args.projectRootPath = root;
}
}
this.client.execute('open', args, false);
......
......@@ -541,7 +541,7 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
isTypeScriptProject: boolean,
resource: Uri
): Thenable<TextEditor | undefined> | undefined {
const rootPath = workspace.rootPath;
const rootPath = this.client.getWorkspaceRootForResource(resource);
if (!rootPath) {
window.showInformationMessage(
localize(
......@@ -588,7 +588,7 @@ class TypeScriptServiceClientHost implements ITypescriptServiceClientHost {
}).then(selected => {
switch (selected && selected.id) {
case ProjectConfigAction.CreateConfig:
return openOrCreateConfigFile(isTypeScriptProject);
return openOrCreateConfigFile(isTypeScriptProject, rootPath);
case ProjectConfigAction.LearnMore:
if (isTypeScriptProject) {
......
......@@ -76,6 +76,7 @@ export class API {
export interface ITypescriptServiceClient {
normalizePath(resource: Uri): string | null;
asUrl(filepath: string): Uri;
getWorkspaceRootForResource(resource: Uri): string | undefined;
warn(message: string, data?: any): void;
......
......@@ -394,7 +394,8 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
}
private get localTypeScriptPath(): string | null {
if (!workspace.rootPath) {
const rootPath = this.mainWorkspaceRootPath;
if (!rootPath) {
return null;
}
......@@ -403,10 +404,10 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
if ((<any>path).isAbsolute(this.configuration.localTsdk)) {
return path.join(this.configuration.localTsdk, 'tsserver.js');
}
return path.join(workspace.rootPath, this.configuration.localTsdk, 'tsserver.js');
return path.join(rootPath, this.configuration.localTsdk, 'tsserver.js');
}
const localModulePath = path.join(workspace.rootPath, 'node_modules', 'typescript', 'lib', 'tsserver.js');
const localModulePath = path.join(rootPath, 'node_modules', 'typescript', 'lib', 'tsserver.js');
if (fs.existsSync(localModulePath) && this.getTypeScriptVersion(localModulePath)) {
return localModulePath;
}
......@@ -418,8 +419,8 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
this._checkGlobalTSCVersion = false;
if ((<any>path).isAbsolute(this.configuration.globalTsdk)) {
return path.join(this.configuration.globalTsdk, 'tsserver.js');
} else if (workspace.rootPath) {
return path.join(workspace.rootPath, this.configuration.globalTsdk, 'tsserver.js');
} else if (this.mainWorkspaceRootPath) {
return path.join(this.mainWorkspaceRootPath, this.configuration.globalTsdk, 'tsserver.js');
}
}
......@@ -435,14 +436,14 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
if (!this.workspaceState.get<boolean>(TypeScriptServiceClient.tsdkMigratedStorageKey, false)) {
this.workspaceState.update(TypeScriptServiceClient.tsdkMigratedStorageKey, true);
if (workspace.rootPath && this.hasWorkspaceTsdkSetting()) {
if (this.mainWorkspaceRootPath && this.hasWorkspaceTsdkSetting()) {
modulePath = this.showVersionPicker(true);
}
}
return modulePath.then(modulePath => {
if (this.workspaceState.get<boolean>(TypeScriptServiceClient.useWorkspaceTsdkStorageKey, false)) {
if (workspace.rootPath) {
if (this.mainWorkspaceRootPath) {
// TODO: check if we need better error handling
return this.localTypeScriptPath || modulePath;
}
......@@ -485,8 +486,8 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
const options: electron.IForkOptions = {
execArgv: [] // [`--debug-brk=5859`]
};
if (workspace.rootPath) {
options.cwd = workspace.rootPath;
if (this.mainWorkspaceRootPath) {
options.cwd = this.mainWorkspaceRootPath;
}
if (debugPort && !isNaN(debugPort)) {
......@@ -622,7 +623,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
private showVersionPicker(firstRun: boolean): Thenable<string> {
const modulePath = this.modulePath || this.globalTypescriptPath;
if (!workspace.rootPath || !modulePath) {
if (!this.mainWorkspaceRootPath || !modulePath) {
return Promise.resolve(modulePath);
}
......@@ -883,6 +884,34 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
return Uri.file(filepath);
}
private get mainWorkspaceRootPath(): string | undefined {
if (workspace.rootPath) {
return workspace.rootPath;
}
if (workspace.workspaceFolders && workspace.workspaceFolders.length) {
return workspace.workspaceFolders[0].fsPath;
}
return undefined;
}
public getWorkspaceRootForResource(resource: Uri): string | undefined {
if (workspace.rootPath) {
return workspace.rootPath;
}
if (workspace.workspaceFolders && workspace.workspaceFolders.length) {
if (resource.scheme === 'file') {
const found = workspace.workspaceFolders.find(root => resource.fsPath.startsWith(root.fsPath));
return found ? found.fsPath : found;
}
return workspace.workspaceFolders[0].fsPath;
}
return undefined;
}
public execute(command: string, args: any, expectsResultOrToken?: boolean | CancellationToken): Promise<any> {
let token: CancellationToken | undefined = undefined;
let expectsResult = true;
......
......@@ -145,7 +145,12 @@ function createLargeProjectMonitorFromTypeScript(item: ExcludeHintItem, client:
vscode.workspace.openTextDocument(configFileName)
.then(vscode.window.showTextDocument);
} else {
openOrCreateConfigFile(configFileName.match(/tsconfig\.?.*\.json/) !== null);
const root = client.getWorkspaceRootForResource(vscode.Uri.file(configFileName));
if (root) {
openOrCreateConfigFile(
configFileName.match(/tsconfig\.?.*\.json/) !== null,
root);
}
}
});
}
......
......@@ -11,13 +11,10 @@ export function isImplicitProjectConfigFile(configFileName: string) {
}
export function openOrCreateConfigFile(
isTypeScriptProject: boolean
isTypeScriptProject: boolean,
rootPath: string
): Thenable<vscode.TextEditor | null> {
if (!vscode.workspace.rootPath) {
return Promise.resolve(null);
}
const configFile = vscode.Uri.file(path.join(vscode.workspace.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;
return vscode.workspace.openTextDocument(configFile)
.then(doc => {
......
......@@ -19,7 +19,7 @@ export default class TsConfigProvider extends vscode.Disposable {
}
public async getConfigsForWorkspace(): Promise<Iterable<string>> {
if (!vscode.workspace.rootPath) {
if (!vscode.workspace.rootPath && !vscode.workspace.workspaceFolders) {
return [];
}
await this.ensureActivated();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册