Skip to content

feat(extension): Update untrusted workspace support from 'false' to '… #1695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ function getProbeLocations(bundled: string): string[] {
* Construct the arguments that's used to spawn the server process.
* @param ctx vscode extension context
*/
function constructArgs(ctx: vscode.ExtensionContext, viewEngine: boolean): string[] {
function constructArgs(
ctx: vscode.ExtensionContext, viewEngine: boolean, isTrustedWorkspace: boolean): string[] {
const config = vscode.workspace.getConfiguration();
const args: string[] = ['--logToConsole'];

Expand Down Expand Up @@ -440,6 +441,10 @@ function constructArgs(ctx: vscode.ExtensionContext, viewEngine: boolean): strin
args.push('--forceStrictTemplates');
}

if (!isTrustedWorkspace) {
args.push('--untrustedWorkspace');
}

const tsdk: string|null = config.get('typescript.tsdk', null);
const tsProbeLocations = [tsdk, ...getProbeLocations(ctx.extensionPath)];
args.push('--tsProbeLocations', tsProbeLocations.join(','));
Expand Down Expand Up @@ -475,7 +480,7 @@ function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.Nod
}

// Node module for the language server
const args = constructArgs(ctx, viewEngine);
const args = constructArgs(ctx, viewEngine, vscode.workspace.isTrusted);
const prodBundle = ctx.asAbsolutePath('server');
const devBundle = ctx.asAbsolutePath(path.join('dist', 'server', 'server.js'));
// VS Code Insider launches extensions in debug mode by default but users
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"capabilities": {
"untrustedWorkspaces": {
"supported": false,
"description": "This extension requires workspace trust because it needs to execute ngcc from the node_modules in the workspace."
"supported": "limited",
"description": "This extension requires workspace trust because it needs to execute ngcc from the node_modules in the workspace. Projects do not require ngcc if all library dependencies are published with partial-Ivy or Full-Ivy."
},
"virtualWorkspaces": {
"supported": "limited",
Expand Down Expand Up @@ -71,7 +71,7 @@
},
{
"command": "angular.runNgcc",
"when": "!virtualWorkspace"
"when": "!virtualWorkspace && isWorkspaceTrusted"
},
{
"command": "angular.getTemplateTcb",
Expand Down
2 changes: 2 additions & 0 deletions server/src/cmdline_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface CommandLineOptions {
includeAutomaticOptionalChainCompletions: boolean;
includeCompletionsWithSnippetText: boolean;
forceStrictTemplates: boolean;
untrustedWorkspace: boolean;
}

export function parseCommandLine(argv: string[]): CommandLineOptions {
Expand All @@ -60,6 +61,7 @@ export function parseCommandLine(argv: string[]): CommandLineOptions {
hasArgument(argv, '--includeAutomaticOptionalChainCompletions'),
includeCompletionsWithSnippetText: hasArgument(argv, '--includeCompletionsWithSnippetText'),
forceStrictTemplates: hasArgument(argv, '--forceStrictTemplates'),
untrustedWorkspace: hasArgument(argv, '--untrustedWorkspace'),
};
}

Expand Down
3 changes: 2 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ function main() {
ngPlugin: '@angular/language-service',
resolvedNgLsPath: ng.resolvedPath,
ivy: isG3 ? true : options.ivy,
disableAutomaticNgcc: options.disableAutomaticNgcc,
disableAutomaticNgcc: options.disableAutomaticNgcc || options.untrustedWorkspace,
logToConsole: options.logToConsole,
includeAutomaticOptionalChainCompletions: options.includeAutomaticOptionalChainCompletions,
includeCompletionsWithSnippetText: options.includeCompletionsWithSnippetText,
forceStrictTemplates: isG3 || options.forceStrictTemplates,
untrustedWorkspace: options.untrustedWorkspace,
});

// Log initialization info
Expand Down
7 changes: 7 additions & 0 deletions server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface SessionOptions {
includeAutomaticOptionalChainCompletions: boolean;
includeCompletionsWithSnippetText: boolean;
forceStrictTemplates: boolean;
untrustedWorkspace: boolean;
}

enum LanguageId {
Expand Down Expand Up @@ -61,6 +62,7 @@ export class Session {
private readonly openFiles = new MruTracker();
private readonly includeAutomaticOptionalChainCompletions: boolean;
private readonly includeCompletionsWithSnippetText: boolean;
private readonly untrustedWorkspace: boolean;
private snippetSupport: boolean|undefined;
// Tracks the spawn order and status of the `ngcc` processes. This allows us to ensure we enable
// the LS in the same order the projects were created in.
Expand All @@ -84,6 +86,7 @@ export class Session {
this.ivy = options.ivy;
this.disableAutomaticNgcc = options.disableAutomaticNgcc;
this.logToConsole = options.logToConsole;
this.untrustedWorkspace = options.untrustedWorkspace;
// Create a connection for the server. The connection uses Node's IPC as a transport.
this.connection = lsp.createConnection({
// cancelUndispatched is a "middleware" to handle all cancellation requests.
Expand Down Expand Up @@ -1133,6 +1136,10 @@ export class Session {
* Disable the language service, run ngcc, then re-enable language service.
*/
private async runNgcc(project: ts.server.Project): Promise<void> {
if (this.untrustedWorkspace) {
this.error('Cannot run ngcc in an untrusted workspace.');
return;
}
if (!isConfiguredProject(project) || this.projectNgccQueue.some(p => p.project === project)) {
return;
}
Expand Down