-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable search of local Typescript Language Service Plugins (fix #45856)…
… (#45858) * Added pluginPaths configuration option to provide additional plugins discovery locations * fixed review comments: added array comparison for tsServerPluginPaths, setting made executable
- Loading branch information
Showing
8 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
export function equals<T>(one: T[], other: T[], itemEquals: (a: T, b: T) => boolean = (a, b) => a === b): boolean { | ||
if (one.length !== other.length) { | ||
return false; | ||
} | ||
|
||
for (let i = 0, len = one.length; i < len; i++) { | ||
if (!itemEquals(one[i], other[i])) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as path from 'path'; | ||
import { workspace } from 'vscode'; | ||
|
||
import { TypeScriptServiceConfiguration } from './configuration'; | ||
import { RelativeWorkspacePathResolver } from './relativePathResolver'; | ||
|
||
export class TypeScriptPluginPathsProvider { | ||
public readonly relativePathResolver: RelativeWorkspacePathResolver = new RelativeWorkspacePathResolver(); | ||
|
||
public constructor( | ||
private configuration: TypeScriptServiceConfiguration | ||
) { } | ||
|
||
public updateConfiguration(configuration: TypeScriptServiceConfiguration): void { | ||
this.configuration = configuration; | ||
} | ||
|
||
public getPluginPaths(): string[] { | ||
const pluginPaths = []; | ||
for (const pluginPath of this.configuration.tsServerPluginPaths) { | ||
pluginPaths.push(...this.resolvePluginPath(pluginPath)); | ||
} | ||
return pluginPaths; | ||
} | ||
|
||
private resolvePluginPath(pluginPath: string): string[] { | ||
if (path.isAbsolute(pluginPath)) { | ||
return [pluginPath]; | ||
} | ||
|
||
const workspacePath = this.relativePathResolver.asAbsoluteWorkspacePath(pluginPath); | ||
if (workspacePath !== undefined) { | ||
return [workspacePath]; | ||
} | ||
|
||
return (workspace.workspaceFolders || []) | ||
.map(workspaceFolder => path.join(workspaceFolder.uri.fsPath, pluginPath)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import * as path from 'path'; | ||
import { workspace } from 'vscode'; | ||
|
||
export class RelativeWorkspacePathResolver { | ||
public asAbsoluteWorkspacePath(relativePath: string): string | undefined { | ||
for (const root of workspace.workspaceFolders || []) { | ||
const rootPrefixes = [`./${root.name}/`, `${root.name}/`, `.\\${root.name}\\`, `${root.name}\\`]; | ||
for (const rootPrefix of rootPrefixes) { | ||
if (relativePath.startsWith(rootPrefix)) { | ||
return path.join(root.uri.fsPath, relativePath.replace(rootPrefix, '')); | ||
} | ||
} | ||
} | ||
|
||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters