diff --git a/ngp-vscode-ng-language-service/build.js b/ngp-vscode-ng-language-service/build.js index 1cc04fb6d09..b86e6b26c0b 100644 --- a/ngp-vscode-ng-language-service/build.js +++ b/ngp-vscode-ng-language-service/build.js @@ -1,23 +1,15 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + const esbuild = require('esbuild'); const fs = require('fs/promises'); const path = require('path'); -const exactExternalPlugin = { - name: 'exact-external', - setup(build) { - const externals = new Set([ - '@angular/compiler', - '@angular/compiler-cli', - '@angular/language-service/api', - ]); - build.onResolve({filter: /^@angular\//}, (args) => { - if (externals.has(args.path)) { - return {path: args.path, external: true}; - } - }); - }, -}; - async function build() { // 1. Build Client console.log('Building client...'); @@ -42,7 +34,6 @@ async function build() { outfile: path.join(__dirname, 'dist/server/server.js'), external: [ path.join(__dirname, '../packages/compiler-cli/preprocessor/ng-analyze/index.js'), - path.join(__dirname, '../packages/compiler-cli/preprocessor/ng-analyze-wasm/ng_analyze.js'), 'typescript', ], alias: { @@ -60,9 +51,6 @@ async function build() { repoRoot, 'packages/language-service/private.ts', ), - '@angular/language-service/api': path.join(repoRoot, 'packages/language-service/api.ts'), - '@angular/language-service': path.join(repoRoot, 'packages/language-service/api.ts'), - '@angular/core': path.join(repoRoot, 'packages/core/index.ts'), }, logOverride: { 'empty-import-meta': 'silent', diff --git a/ngp-vscode-ng-language-service/client/package.json b/ngp-vscode-ng-language-service/client/package.json index 1beee466e93..c346a81518a 100644 --- a/ngp-vscode-ng-language-service/client/package.json +++ b/ngp-vscode-ng-language-service/client/package.json @@ -3,10 +3,6 @@ "version": "0.0.1", "private": true, "main": "out/extension.js", - "scripts": { - "compile": "tsc -p .", - "watch": "tsc -p . -w" - }, "dependencies": { "vscode-languageclient": "^10.1.0" }, diff --git a/ngp-vscode-ng-language-service/client/src/commands.ts b/ngp-vscode-ng-language-service/client/src/commands.ts index fca4ee8541e..aea3df4fcb2 100644 --- a/ngp-vscode-ng-language-service/client/src/commands.ts +++ b/ngp-vscode-ng-language-service/client/src/commands.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as vscode from 'vscode'; import {LanguageClient} from 'vscode-languageclient/node'; diff --git a/ngp-vscode-ng-language-service/client/src/extension.ts b/ngp-vscode-ng-language-service/client/src/extension.ts index 5b43ad9c7f5..05b20569142 100644 --- a/ngp-vscode-ng-language-service/client/src/extension.ts +++ b/ngp-vscode-ng-language-service/client/src/extension.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as path from 'path'; import * as vscode from 'vscode'; import { @@ -69,7 +77,7 @@ export async function activate(context: vscode.ExtensionContext) { registerCommands(context, client, outputChannel); - const startAngularClientPromise = client.start().catch((err) => { + client.start().catch((err) => { outputChannel.appendLine(`Failed to start Angular Language Service: ${err}`); }); diff --git a/ngp-vscode-ng-language-service/e2e/build-tests.js b/ngp-vscode-ng-language-service/e2e/build-tests.js index db515f5ac19..d8a682fbb14 100644 --- a/ngp-vscode-ng-language-service/e2e/build-tests.js +++ b/ngp-vscode-ng-language-service/e2e/build-tests.js @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + const esbuild = require('esbuild'); const path = require('path'); const fs = require('fs/promises'); diff --git a/ngp-vscode-ng-language-service/e2e/runTests.js b/ngp-vscode-ng-language-service/e2e/runTests.js index bc066cfdba3..9a318e12433 100644 --- a/ngp-vscode-ng-language-service/e2e/runTests.js +++ b/ngp-vscode-ng-language-service/e2e/runTests.js @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + const path = require('path'); const {runTests} = require('@vscode/test-electron'); diff --git a/ngp-vscode-ng-language-service/e2e/src/definition.ts b/ngp-vscode-ng-language-service/e2e/src/definition.ts index 11014a88695..e1b1ee61d10 100644 --- a/ngp-vscode-ng-language-service/e2e/src/definition.ts +++ b/ngp-vscode-ng-language-service/e2e/src/definition.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as vscode from 'vscode'; import * as assert from 'assert'; import * as path from 'path'; diff --git a/ngp-vscode-ng-language-service/e2e/src/diagnostics.ts b/ngp-vscode-ng-language-service/e2e/src/diagnostics.ts index 57ed637f01a..929cf7122d8 100644 --- a/ngp-vscode-ng-language-service/e2e/src/diagnostics.ts +++ b/ngp-vscode-ng-language-service/e2e/src/diagnostics.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as vscode from 'vscode'; import * as assert from 'assert'; import * as path from 'path'; diff --git a/ngp-vscode-ng-language-service/e2e/src/diagnostics_ext.ts b/ngp-vscode-ng-language-service/e2e/src/diagnostics_ext.ts index c8e0dadb72c..d5b8fc1a7d9 100644 --- a/ngp-vscode-ng-language-service/e2e/src/diagnostics_ext.ts +++ b/ngp-vscode-ng-language-service/e2e/src/diagnostics_ext.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as vscode from 'vscode'; import * as assert from 'assert'; import * as path from 'path'; diff --git a/ngp-vscode-ng-language-service/e2e/src/getTcb.ts b/ngp-vscode-ng-language-service/e2e/src/getTcb.ts index b167eae7995..7522f084207 100644 --- a/ngp-vscode-ng-language-service/e2e/src/getTcb.ts +++ b/ngp-vscode-ng-language-service/e2e/src/getTcb.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as vscode from 'vscode'; import * as path from 'path'; import * as assert from 'assert'; diff --git a/ngp-vscode-ng-language-service/e2e/src/hover.ts b/ngp-vscode-ng-language-service/e2e/src/hover.ts index 9aebcb96bdf..ec6a5cb8589 100644 --- a/ngp-vscode-ng-language-service/e2e/src/hover.ts +++ b/ngp-vscode-ng-language-service/e2e/src/hover.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as vscode from 'vscode'; import * as assert from 'assert'; import * as path from 'path'; diff --git a/ngp-vscode-ng-language-service/e2e/src/index.ts b/ngp-vscode-ng-language-service/e2e/src/index.ts index 092b6cb848a..e71862d1e1c 100644 --- a/ngp-vscode-ng-language-service/e2e/src/index.ts +++ b/ngp-vscode-ng-language-service/e2e/src/index.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as path from 'path'; import * as fs from 'fs/promises'; diff --git a/ngp-vscode-ng-language-service/e2e/src/utils.ts b/ngp-vscode-ng-language-service/e2e/src/utils.ts index ed2c6ed31b2..eca31188450 100644 --- a/ngp-vscode-ng-language-service/e2e/src/utils.ts +++ b/ngp-vscode-ng-language-service/e2e/src/utils.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + export interface WaitForOptions { timeout?: number; interval?: number; diff --git a/ngp-vscode-ng-language-service/e2e/test-workspace/app.ts b/ngp-vscode-ng-language-service/e2e/test-workspace/app.ts index 6395782bdba..005e23eb82f 100644 --- a/ngp-vscode-ng-language-service/e2e/test-workspace/app.ts +++ b/ngp-vscode-ng-language-service/e2e/test-workspace/app.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {Component, Directive, Input, signal} from '@angular/core'; import {MyAttrDirective} from './my-attr.directive'; import {MatListItemStub} from './mat-list-item.component'; diff --git a/ngp-vscode-ng-language-service/e2e/test-workspace/directive_hover.ts b/ngp-vscode-ng-language-service/e2e/test-workspace/directive_hover.ts index 83b0f263998..8c14d1f5383 100644 --- a/ngp-vscode-ng-language-service/e2e/test-workspace/directive_hover.ts +++ b/ngp-vscode-ng-language-service/e2e/test-workspace/directive_hover.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {Component, signal} from '@angular/core'; @Component({ diff --git a/ngp-vscode-ng-language-service/e2e/test-workspace/incremental.ts b/ngp-vscode-ng-language-service/e2e/test-workspace/incremental.ts index 8647885dc8f..217fad38dc9 100644 --- a/ngp-vscode-ng-language-service/e2e/test-workspace/incremental.ts +++ b/ngp-vscode-ng-language-service/e2e/test-workspace/incremental.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {Component} from '@angular/core'; @Component({ diff --git a/ngp-vscode-ng-language-service/e2e/test-workspace/mat-list-item.component.ts b/ngp-vscode-ng-language-service/e2e/test-workspace/mat-list-item.component.ts index 49b0ad386f8..62ba7682673 100644 --- a/ngp-vscode-ng-language-service/e2e/test-workspace/mat-list-item.component.ts +++ b/ngp-vscode-ng-language-service/e2e/test-workspace/mat-list-item.component.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {Component, Input} from '@angular/core'; @Component({ diff --git a/ngp-vscode-ng-language-service/e2e/test-workspace/my-attr.directive.ts b/ngp-vscode-ng-language-service/e2e/test-workspace/my-attr.directive.ts index d87b3e6376d..a130d123aca 100644 --- a/ngp-vscode-ng-language-service/e2e/test-workspace/my-attr.directive.ts +++ b/ngp-vscode-ng-language-service/e2e/test-workspace/my-attr.directive.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {Directive} from '@angular/core'; @Directive({ diff --git a/ngp-vscode-ng-language-service/server/package.json b/ngp-vscode-ng-language-service/server/package.json index d636865daf9..86beb15ee48 100644 --- a/ngp-vscode-ng-language-service/server/package.json +++ b/ngp-vscode-ng-language-service/server/package.json @@ -3,10 +3,6 @@ "version": "0.0.1", "private": true, "main": "out/server.js", - "scripts": { - "compile": "tsc -p .", - "watch": "tsc -p . -w" - }, "dependencies": { "@typescript/native-preview": "7.0.0-dev.20260707.2", "vscode-languageserver": "^10.1.0", diff --git a/ngp-vscode-ng-language-service/server/src/diagnostic_publisher.ts b/ngp-vscode-ng-language-service/server/src/diagnostic_publisher.ts index db7a820bfdc..f1fba081763 100644 --- a/ngp-vscode-ng-language-service/server/src/diagnostic_publisher.ts +++ b/ngp-vscode-ng-language-service/server/src/diagnostic_publisher.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {Connection} from 'vscode-languageserver/node'; import {URI} from 'vscode-uri'; import {fileURLToPath} from 'node:url'; diff --git a/ngp-vscode-ng-language-service/server/src/handlers/completion.ts b/ngp-vscode-ng-language-service/server/src/handlers/completion.ts index 8b4ae8e5136..10f8ca8337b 100644 --- a/ngp-vscode-ng-language-service/server/src/handlers/completion.ts +++ b/ngp-vscode-ng-language-service/server/src/handlers/completion.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {CompletionParams, CompletionList, CompletionItem} from 'vscode-languageserver'; import {HandlerContext, getDocumentContext} from './utils.js'; diff --git a/ngp-vscode-ng-language-service/server/src/handlers/definition.ts b/ngp-vscode-ng-language-service/server/src/handlers/definition.ts index 90bdd916e97..020569c7493 100644 --- a/ngp-vscode-ng-language-service/server/src/handlers/definition.ts +++ b/ngp-vscode-ng-language-service/server/src/handlers/definition.ts @@ -1,8 +1,14 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {DefinitionParams, Definition, LocationLink} from 'vscode-languageserver'; import {HandlerContext, getDocumentContext} from './utils.js'; -export {HandlerContext}; - export async function onDefinition(params: DefinitionParams, context: HandlerContext) { const docContext = getDocumentContext(context, params.textDocument.uri, params.position); if (!docContext) { diff --git a/ngp-vscode-ng-language-service/server/src/handlers/hover.ts b/ngp-vscode-ng-language-service/server/src/handlers/hover.ts index 32d0416d305..1786b7de239 100644 --- a/ngp-vscode-ng-language-service/server/src/handlers/hover.ts +++ b/ngp-vscode-ng-language-service/server/src/handlers/hover.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {HandlerContext, getDocumentContext} from './utils.js'; import {offsetToPosition} from '../../../../packages/compiler-cli/preprocessor/src/tcb_ls_util.js'; diff --git a/ngp-vscode-ng-language-service/server/src/handlers/tcb.ts b/ngp-vscode-ng-language-service/server/src/handlers/tcb.ts index a810f5da741..d1b5bd38a3a 100644 --- a/ngp-vscode-ng-language-service/server/src/handlers/tcb.ts +++ b/ngp-vscode-ng-language-service/server/src/handlers/tcb.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import {fileURLToPath} from 'node:url'; import {HandlerContext} from './utils.js'; diff --git a/ngp-vscode-ng-language-service/server/src/handlers/utils.ts b/ngp-vscode-ng-language-service/server/src/handlers/utils.ts index e7331db4cf4..8f8a7491c3c 100644 --- a/ngp-vscode-ng-language-service/server/src/handlers/utils.ts +++ b/ngp-vscode-ng-language-service/server/src/handlers/utils.ts @@ -6,16 +6,14 @@ * found in the LICENSE file at https://angular.dev/license */ -import {Position, TextDocuments, Connection} from 'vscode-languageserver'; +import {Position, TextDocuments} from 'vscode-languageserver'; import {TextDocument} from 'vscode-languageserver-textdocument'; import {fileURLToPath} from 'node:url'; import {LanguageService} from '../../../../packages/compiler-cli/preprocessor/language-service/src/language_service.js'; import {positionToOffset} from '../../../../packages/compiler-cli/preprocessor/src/tcb_ls_util.js'; export interface HandlerContext { - workspaceRoot: string; languageService: LanguageService; - connection: Connection; documents: TextDocuments; } diff --git a/ngp-vscode-ng-language-service/server/src/project_manager.ts b/ngp-vscode-ng-language-service/server/src/project_manager.ts index 748c9ebac05..717f2bef36c 100644 --- a/ngp-vscode-ng-language-service/server/src/project_manager.ts +++ b/ngp-vscode-ng-language-service/server/src/project_manager.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as fs from 'node:fs/promises'; import {readConfiguration} from '@angular/compiler-cli'; import {API, Snapshot} from '@typescript/native-preview/unstable/async'; @@ -56,10 +64,6 @@ export class ProjectManager { this.currentSnapshot = undefined; } - getApi(): API | undefined { - return this.api; - } - getLoadedProjects(): readonly ProjectInstance[] { return Array.from(this.projects.values()); } diff --git a/ngp-vscode-ng-language-service/server/src/server.ts b/ngp-vscode-ng-language-service/server/src/server.ts index b6b0809af1c..74b260d0078 100644 --- a/ngp-vscode-ng-language-service/server/src/server.ts +++ b/ngp-vscode-ng-language-service/server/src/server.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import { createConnection, ProposedFeatures, @@ -40,7 +48,6 @@ import {ProjectManager} from './project_manager'; import {DiagnosticPublisher} from './diagnostic_publisher'; import {canonicalizePath as normalizePath} from '../../../packages/compiler-cli/preprocessor/language-service/src/utils.js'; -let workspaceRoot: string = ''; let facade: TsGoFacade | null = null; let projectManager: ProjectManager | null = null; @@ -133,11 +140,6 @@ connection.onDidChangeWatchedFiles((params: DidChangeWatchedFilesParams) => { connection.onInitialize(async (params: InitializeParams) => { connection.console.log(`Initializing Angular Hybrid Language Server`); - if (params.rootUri) { - workspaceRoot = fileURLToPath(params.rootUri); - } else if (params.rootPath) { - workspaceRoot = params.rootPath; - } let api: API | undefined; if (params.initializationOptions?.tsApiPipe) { @@ -230,9 +232,7 @@ function withProject

( if (!info) return null; await info.project.hybridCompiler.ensureReady(); return handler(params, { - workspaceRoot, languageService: info.project.languageService, - connection, documents, }); }; @@ -252,9 +252,7 @@ connection.onCompletionResolve(async (item: CompletionItem) => { if (project) { await project.hybridCompiler.ensureReady(); return onCompletionResolve(item, { - workspaceRoot, languageService: project.languageService, - connection, documents, }); } diff --git a/ngp-vscode-ng-language-service/tests/incremental_lsp_spec.ts b/ngp-vscode-ng-language-service/tests/incremental_lsp_spec.ts index 786880c1c06..b447b2eb1e0 100644 --- a/ngp-vscode-ng-language-service/tests/incremental_lsp_spec.ts +++ b/ngp-vscode-ng-language-service/tests/incremental_lsp_spec.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as rpc from 'vscode-jsonrpc/node'; import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers'; import {TestFileManager} from '../../packages/compiler-cli/preprocessor/language-service/tests/test_file_manager'; diff --git a/ngp-vscode-ng-language-service/tests/lsp_completions_spec.ts b/ngp-vscode-ng-language-service/tests/lsp_completions_spec.ts index 71d31a11175..9625757d256 100644 --- a/ngp-vscode-ng-language-service/tests/lsp_completions_spec.ts +++ b/ngp-vscode-ng-language-service/tests/lsp_completions_spec.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as rpc from 'vscode-jsonrpc/node'; import {CompletionItemKind} from 'vscode-languageserver'; import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers'; diff --git a/ngp-vscode-ng-language-service/tests/lsp_diagnostics_spec.ts b/ngp-vscode-ng-language-service/tests/lsp_diagnostics_spec.ts index 27d4c8a4484..cc4d4ac70ab 100644 --- a/ngp-vscode-ng-language-service/tests/lsp_diagnostics_spec.ts +++ b/ngp-vscode-ng-language-service/tests/lsp_diagnostics_spec.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as rpc from 'vscode-jsonrpc/node'; import {URI} from 'vscode-uri'; import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers'; diff --git a/ngp-vscode-ng-language-service/tests/lsp_references_and_rename_spec.ts b/ngp-vscode-ng-language-service/tests/lsp_references_and_rename_spec.ts index f9b6d7fc58a..4df9cb805f5 100644 --- a/ngp-vscode-ng-language-service/tests/lsp_references_and_rename_spec.ts +++ b/ngp-vscode-ng-language-service/tests/lsp_references_and_rename_spec.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as rpc from 'vscode-jsonrpc/node'; import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers'; import {TestFileManager} from '../../packages/compiler-cli/preprocessor/language-service/tests/test_file_manager'; diff --git a/ngp-vscode-ng-language-service/tests/lsp_signature_help_spec.ts b/ngp-vscode-ng-language-service/tests/lsp_signature_help_spec.ts index d2309f703d2..af79e33b841 100644 --- a/ngp-vscode-ng-language-service/tests/lsp_signature_help_spec.ts +++ b/ngp-vscode-ng-language-service/tests/lsp_signature_help_spec.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as path from 'path'; import * as rpc from 'vscode-jsonrpc/node'; import {TestEnv, getTestWorkspacePath, startTestServer} from './test_helpers'; diff --git a/ngp-vscode-ng-language-service/tests/multi_project_spec.ts b/ngp-vscode-ng-language-service/tests/multi_project_spec.ts index dc717a9184f..629306d48f0 100644 --- a/ngp-vscode-ng-language-service/tests/multi_project_spec.ts +++ b/ngp-vscode-ng-language-service/tests/multi_project_spec.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as path from 'path'; import * as fs from 'node:fs/promises'; import * as rpc from 'vscode-jsonrpc/node'; diff --git a/ngp-vscode-ng-language-service/tests/test_helpers.ts b/ngp-vscode-ng-language-service/tests/test_helpers.ts index 358b4440ea4..dbb9266b49d 100644 --- a/ngp-vscode-ng-language-service/tests/test_helpers.ts +++ b/ngp-vscode-ng-language-service/tests/test_helpers.ts @@ -1,3 +1,11 @@ +/*! + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + import * as path from 'path'; import * as fs from 'node:fs/promises'; import * as cp from 'child_process'; @@ -374,13 +382,6 @@ export class TestEnv { this.openedFiles.push(normPath); } - async updateFiles(updates: {filePath: string; text: string; version: number}[]) { - for (const update of updates) { - const normPath = await normalizePath(update.filePath); - await this.lspClient.didChange(normPath, update.text, update.version); - } - } - async closeFile(filePath: string) { const normPath = await normalizePath(filePath); this.openedFiles = this.openedFiles.filter((u) => u !== normPath); @@ -462,16 +463,6 @@ export class TestEnv { } } - async expectDefinitionAtCursor(filePath: string, expectedFileName: string) { - const {normPath, position} = await this.getCursorContext(filePath); - const result = await this.lspClient.definition(normPath, position); - - expect(result).toBeTruthy(); - const locations = Array.isArray(result) ? result : [result]; - const fileNames = locations.map((l: any) => l.uri || l.targetUri); - expect(fileNames.some((f: string) => f && f.includes(expectedFileName))).toBe(true); - } - async expectDiagnostics(filePath: string, expectedMessages: string[]) { const normPath = await normalizePath(filePath); const result = await this.lspClient.diagnostic(normPath); diff --git a/ngp-vscode-ng-language-service/tsconfig.json b/ngp-vscode-ng-language-service/tsconfig.json index bc2aef493a3..2e3637065bb 100644 --- a/ngp-vscode-ng-language-service/tsconfig.json +++ b/ngp-vscode-ng-language-service/tsconfig.json @@ -14,9 +14,6 @@ "@angular/compiler-cli": ["../packages/compiler-cli/index.ts"], "@angular/compiler": ["../packages/compiler/index.ts"], "@angular/language-service/private": ["../packages/language-service/private.ts"], - "@angular/language-service/api": ["../packages/language-service/api.ts"], - "@angular/language-service": ["../packages/language-service/api.ts"], - "@angular/core": ["../packages/core/index.ts"], "vscode-languageserver": ["node_modules/vscode-languageserver/lib/common/api.d.ts"], "vscode-languageserver/*": ["node_modules/vscode-languageserver/*"], "vscode-uri": ["node_modules/vscode-uri"] diff --git a/packages/compiler-cli/preprocessor/language-service/src/attribute_completions.ts b/packages/compiler-cli/preprocessor/language-service/src/attribute_completions.ts index 25dd60a0ddb..da470021374 100644 --- a/packages/compiler-cli/preprocessor/language-service/src/attribute_completions.ts +++ b/packages/compiler-cli/preprocessor/language-service/src/attribute_completions.ts @@ -9,7 +9,6 @@ import { CssSelector, DomElementSchemaRegistry, - MatchSource, SelectorMatcher, TmplAstElement, TmplAstTemplate, @@ -36,7 +35,6 @@ const REGISTRY = new DomElementSchemaRegistry(); */ export enum AttributeCompletionKind { DomAttribute, - DomProperty, DomEvent, DirectiveAttribute, StructuralDirectiveAttribute, @@ -50,11 +48,6 @@ export interface DomAttributeCompletion { isAlsoProperty: true; } -export interface DomPropertyCompletion { - kind: AttributeCompletionKind.DomProperty; - property: string; -} - export interface DomEventCompletion { kind: AttributeCompletionKind.DomEvent; eventName: string; @@ -85,7 +78,6 @@ export interface DirectiveOutputCompletion { export type AttributeCompletion = | DomAttributeCompletion - | DomPropertyCompletion | DirectiveAttributeCompletion | DirectiveInputCompletion | DirectiveOutputCompletion @@ -575,33 +567,6 @@ export function addAttributeCompletionEntries( } break; } - case AttributeCompletionKind.DomProperty: { - if (!isAttributeContext) { - entries.push( - createItem( - completion.property, - CompletionItemKind.Property, - completion.property, - insertSnippet, - buildSnippet(insertSnippet, completion.property), - replacementRange, - ), - ); - if (insertSnippet) { - entries.push( - createItem( - `[${completion.property}]`, - CompletionItemKind.Property, - completion.property + '_1', - insertSnippet, - buildSnippet(insertSnippet, `[${completion.property}]`), - replacementRange, - ), - ); - } - } - break; - } case AttributeCompletionKind.DomEvent: { if (isAttributeContext) { entries.push( diff --git a/packages/compiler-cli/preprocessor/language-service/src/completions.ts b/packages/compiler-cli/preprocessor/language-service/src/completions.ts index fb26c5d723d..0abe9de696d 100644 --- a/packages/compiler-cli/preprocessor/language-service/src/completions.ts +++ b/packages/compiler-cli/preprocessor/language-service/src/completions.ts @@ -68,7 +68,6 @@ import { } from '@angular/language-service/private'; import {isBoundEventWithSyntheticHandler, isWithin} from './utils.js'; import {HybridCompiler} from '../../src/hybrid_compiler.js'; -import {TemplateTypeChecker} from './type_checker.js'; import {TsGoFacade} from './facade.js'; import {getSetup, SetupResult} from './type_checker_setup.js'; import {offsetToPosition} from '../../src/tcb_ls_util.js'; @@ -82,10 +81,7 @@ export enum CompletionNodeContext { TwoWayBinding, } -function buildBlockSnippet(insertSnippet: boolean, blockName: string, withParens: boolean): string { - if (!insertSnippet) { - return blockName; - } +function buildBlockSnippet(blockName: string, withParens: boolean): string { if (blockName === 'for') { return `${blockName} (\${1:item} of \${2:items}; track \${3:\\$index}) {$4}`; } @@ -99,12 +95,10 @@ export class CompletionBuilder { private readonly node: AST | TmplAstNode; private readonly nodeParent: AST | TmplAstNode | null; private readonly nodeContext: CompletionNodeContext; - private readonly template: TmplAstTemplate | null; private readonly position: number; constructor( private readonly hybridCompiler: HybridCompiler, - private readonly templateTypeChecker: TemplateTypeChecker, private readonly facade: TsGoFacade, private readonly setup: SetupResult, private readonly targetDetails: TemplateTarget, @@ -115,7 +109,6 @@ export class CompletionBuilder { : this.targetDetails.context.node; this.nodeParent = this.targetDetails.parent; this.nodeContext = nodeContextFromTarget(this.targetDetails.context); - this.template = this.targetDetails.template; this.position = this.targetDetails.position; } @@ -491,7 +484,6 @@ export class CompletionBuilder { if (this.node instanceof TmplAstBoundAttribute) continue; break; case AttributeCompletionKind.DomAttribute: - case AttributeCompletionKind.DomProperty: if (this.node instanceof TmplAstBoundEvent) continue; break; case AttributeCompletionKind.DirectiveInput: @@ -665,15 +657,6 @@ export class CompletionBuilder { } private getBlockCompletions(): CompletionList | null { - let hasLeadingAt = false; - if (this.node instanceof TmplAstText) { - const positionInText = this.position - this.node.sourceSpan.start.offset; - const textToLeft = this.node.value.substring(0, positionInText); - hasLeadingAt = Boolean(textToLeft.match(/(?:^|\s)@[a-zA-Z]*$/)); - } else if (this.node instanceof TmplAstElement) { - hasLeadingAt = this.node.name.startsWith('@'); - } - let blocks: {name: string; withParens: boolean}[]; if (this.nodeParent instanceof TmplAstSwitchBlock || this.node instanceof TmplAstSwitchBlock) { blocks = [ @@ -691,8 +674,7 @@ export class CompletionBuilder { const items: CompletionItem[] = blocks.map((b) => { const label = b.name; - const insertSnippet = true; - const snippet = buildBlockSnippet(insertSnippet, b.name, b.withParens); + const snippet = buildBlockSnippet(b.name, b.withParens); return { label, kind: CompletionItemKind.Keyword, @@ -927,9 +909,7 @@ export async function getCompletionsAtPosition( filePath: string, offset: number, position: {line: number; character: number}, - fileContent: string, hybridCompiler: HybridCompiler, - templateTypeChecker: TemplateTypeChecker, facade: TsGoFacade, ): Promise { const setup = getSetup(hybridCompiler, filePath, position); @@ -993,13 +973,7 @@ export async function getCompletionsAtPosition( return null; } - const builder = new CompletionBuilder( - hybridCompiler, - templateTypeChecker, - facade, - setup, - targetDetails, - ); + const builder = new CompletionBuilder(hybridCompiler, facade, setup, targetDetails); return builder.getCompletions(); } @@ -1007,9 +981,7 @@ export async function getCompletionEntryDetails( filePath: string, offset: number, position: {line: number; character: number}, - fileContent: string, hybridCompiler: HybridCompiler, - templateTypeChecker: TemplateTypeChecker, facade: TsGoFacade, item: CompletionItem | string, ): Promise { @@ -1028,13 +1000,7 @@ export async function getCompletionEntryDetails( return null; } - const builder = new CompletionBuilder( - hybridCompiler, - templateTypeChecker, - facade, - setup, - targetDetails, - ); + const builder = new CompletionBuilder(hybridCompiler, facade, setup, targetDetails); const completionItem: CompletionItem = typeof item === 'string' ? {label: item} : item; diff --git a/packages/compiler-cli/preprocessor/language-service/src/definitions.ts b/packages/compiler-cli/preprocessor/language-service/src/definitions.ts index 65b2af219fa..8268cb15834 100644 --- a/packages/compiler-cli/preprocessor/language-service/src/definitions.ts +++ b/packages/compiler-cli/preprocessor/language-service/src/definitions.ts @@ -46,7 +46,7 @@ export class DefinitionBuilder { if (!setup) { return null; } - const {tsFilePath, parsedTemplate, isHostBinding, hostElement} = setup; + const {parsedTemplate, isHostBinding, hostElement} = setup; let target; if (isHostBinding && hostElement) { diff --git a/packages/compiler-cli/preprocessor/language-service/src/facade.ts b/packages/compiler-cli/preprocessor/language-service/src/facade.ts index 6eac9de4274..abbbb8910b0 100644 --- a/packages/compiler-cli/preprocessor/language-service/src/facade.ts +++ b/packages/compiler-cli/preprocessor/language-service/src/facade.ts @@ -21,7 +21,6 @@ import { import * as rpc from 'vscode-jsonrpc/node'; import {URI} from 'vscode-uri'; import {fileURLToPath} from 'node:url'; -import * as path from 'node:path'; export interface StructuralQuickInfo { text: string; diff --git a/packages/compiler-cli/preprocessor/language-service/src/hover.ts b/packages/compiler-cli/preprocessor/language-service/src/hover.ts index ed590409e35..7dc6ed68110 100644 --- a/packages/compiler-cli/preprocessor/language-service/src/hover.ts +++ b/packages/compiler-cli/preprocessor/language-service/src/hover.ts @@ -18,7 +18,7 @@ import { createDollarAnyQuickInfo, createNgTemplateQuickInfo, } from './quick_info_built_ins.js'; -import {getTextSpanOfNode, getDirectiveMatchesForAttribute} from './utils.js'; +import {getTextSpanOfNode, getDirectiveMatchesForAttribute, isWithin} from './utils.js'; import {offsetToPosition} from '../../src/tcb_ls_util.js'; import { PropertyRead, @@ -52,7 +52,7 @@ export async function getHover( if (!setup) { return null; } - const {tsFilePath, parsedTemplate, isHostBinding, hostElement} = setup; + const {parsedTemplate, isHostBinding, hostElement} = setup; let target; if (isHostBinding && hostElement) { @@ -396,13 +396,6 @@ function cleanupTcbText( return `${code}${doc}`; } -function isWithin( - position: number, - span: {start: {offset: number}; end: {offset: number}}, -): boolean { - return span.start.offset <= position && position < span.end.offset; -} - function createQuickInfoForBuiltIn( node: AST | TmplAstNode | null, offset: number, diff --git a/packages/compiler-cli/preprocessor/language-service/src/language_service.ts b/packages/compiler-cli/preprocessor/language-service/src/language_service.ts index 11db3b61a67..36e17241527 100644 --- a/packages/compiler-cli/preprocessor/language-service/src/language_service.ts +++ b/packages/compiler-cli/preprocessor/language-service/src/language_service.ts @@ -34,21 +34,6 @@ export class LanguageService { this.templateTypeChecker = new TemplateTypeChecker(hybridCompiler); } - // Standalone LSP runs in angularOnly mode because the default TS server handles regular TS code. - // https://github.com/angular/angular/blob/d27e2c2/packages/language-service/src/ts_plugin.ts#L38-L46 - private readonly angularOnly = true; - private async withFallback( - filePath: string, - tsOp: () => Promise, - ngOp: () => Promise, - ): Promise { - if (this.angularOnly || !filePath.endsWith('.ts')) { - return await ngOp(); - } - - return (await tsOp()) ?? ngOp(); - } - async getHover( filePath: string, offset: number, @@ -56,22 +41,14 @@ export class LanguageService { fileContent: string, ): Promise<{text: string; span?: {start: number; length: number}} | null> { await this.hybridCompiler.ensureReady(); - return this.withFallback<{text: string; span?: {start: number; length: number}}>( + return getHover( filePath, - async () => { - const result = await this.facade.getQuickInfoAtPosition(filePath, position); - return result ? {text: result.text} : null; - }, - () => - getHover( - filePath, - offset, - position, - fileContent, - this.hybridCompiler, - this.templateTypeChecker, - this.facade, - ), + offset, + position, + fileContent, + this.hybridCompiler, + this.templateTypeChecker, + this.facade, ); } @@ -83,19 +60,14 @@ export class LanguageService { fileContent: string, ): Promise { await this.hybridCompiler.ensureReady(); - return this.withFallback( + return getDefinition( filePath, - () => this.facade.getDefinitionAtPosition(filePath, position), - () => - getDefinition( - filePath, - offset, - position, - fileContent, - this.hybridCompiler, - this.templateTypeChecker, - this.facade, - ), + offset, + position, + fileContent, + this.hybridCompiler, + this.templateTypeChecker, + this.facade, ); } @@ -108,25 +80,17 @@ export class LanguageService { filePath: string, offset: number, position: {line: number; character: number}, - fileContent: string, + _fileContent?: string, ): Promise { await this.hybridCompiler.ensureReady(); - return getCompletionsAtPosition( - filePath, - offset, - position, - fileContent, - this.hybridCompiler, - this.templateTypeChecker, - this.facade, - ); + return getCompletionsAtPosition(filePath, offset, position, this.hybridCompiler, this.facade); } async getCompletionEntryDetails( filePath: string, offset: number, position: {line: number; character: number}, - fileContent: string, + _fileContent: string, item: CompletionItem | string, ): Promise { await this.hybridCompiler.ensureReady(); @@ -134,9 +98,7 @@ export class LanguageService { filePath, offset, position, - fileContent, this.hybridCompiler, - this.templateTypeChecker, this.facade, item, ); @@ -195,20 +157,15 @@ export class LanguageService { context?: SignatureHelpContext, ): Promise { await this.hybridCompiler.ensureReady(); - return this.withFallback( + return getSignatureHelp( filePath, - () => this.facade.getSignatureHelpAtPosition(filePath, position, context), - () => - getSignatureHelp( - filePath, - offset, - position, - fileContent, - this.hybridCompiler, - this.templateTypeChecker, - this.facade, - context, - ), + offset, + position, + fileContent, + this.hybridCompiler, + this.templateTypeChecker, + this.facade, + context, ); } } diff --git a/packages/compiler-cli/preprocessor/language-service/tests/diagnostics_spec.ts b/packages/compiler-cli/preprocessor/language-service/tests/diagnostics_spec.ts index afc07439cb8..87d9644d51e 100644 --- a/packages/compiler-cli/preprocessor/language-service/tests/diagnostics_spec.ts +++ b/packages/compiler-cli/preprocessor/language-service/tests/diagnostics_spec.ts @@ -115,7 +115,7 @@ describe('Diagnostics Mapping', () => { } `; - env.createFile('app.html', appHtmlContent); + await env.createFile('app.html', appHtmlContent); await env.run('app_diagnostics_ext_test.ts', appTsContent, async (ls, filePath) => { const htmlPath = path.join(testWorkspacePath, 'app.html'); diff --git a/packages/compiler-cli/preprocessor/language-service/tests/test_file_manager.ts b/packages/compiler-cli/preprocessor/language-service/tests/test_file_manager.ts index 9fca02311ea..3cf7bcc7b47 100644 --- a/packages/compiler-cli/preprocessor/language-service/tests/test_file_manager.ts +++ b/packages/compiler-cli/preprocessor/language-service/tests/test_file_manager.ts @@ -13,7 +13,6 @@ export class TestFileManager { private files: string[] = []; private virtualFiles: Record = {}; private cursorOffset?: number; - private currentVersion = 0; constructor(private workspacePath: string) {} @@ -98,18 +97,6 @@ export class TestFileManager { getFiles(): string[] { return this.files; } - - getVirtualFiles(): Record { - return this.virtualFiles; - } - - incrementVersion(): number { - return ++this.currentVersion; - } - - getCurrentVersion(): number { - return this.currentVersion; - } } export function extractCursorInfo(content: string): {cursorOffset?: number; text: string} { diff --git a/packages/compiler-cli/preprocessor/language-service/tests/test_helpers.ts b/packages/compiler-cli/preprocessor/language-service/tests/test_helpers.ts index 01cc5cbff92..ec509fdb748 100644 --- a/packages/compiler-cli/preprocessor/language-service/tests/test_helpers.ts +++ b/packages/compiler-cli/preprocessor/language-service/tests/test_helpers.ts @@ -34,7 +34,7 @@ import {URI} from 'vscode-uri'; import {fileURLToPath} from 'node:url'; import {createRequire} from 'node:module'; import {canonicalizePath} from '../src/utils.js'; -import {TestFileManager} from './test_file_manager'; +import {TestFileManager} from './test_file_manager.js'; /** Directory containing this file (and the spec files). */ const TESTS_DIR = path.dirname(fileURLToPath(import.meta.url)); @@ -166,25 +166,8 @@ export async function resolveTsGoPath(): Promise { const platformName = `@typescript/native-preview-${process.platform}-${process.arch}`; const localCandidates = [ path.join(workspaceRoot, 'node_modules', platformName, 'lib', 'tsgo'), - path.join( - workspaceRoot, - 'reference', - 'typescript-go', - 'built', - 'local', - `tsgo${process.platform === 'win32' ? '.exe' : ''}`, - ), path.join(workspaceRoot, 'node_modules', '@typescript', 'native-preview', 'bin', 'tsgo.js'), path.join(workspaceRoot, 'node_modules', '@typescript', 'native-preview', 'bin', 'tsgo'), - path.join( - workspaceRoot, - 'reference', - 'typescript-go', - '_packages', - 'native-preview', - 'bin', - 'tsgo', - ), ]; for (const candidate of localCandidates) { @@ -314,18 +297,6 @@ export class TestEnv { this.openedFiles.push(cleanPath); } - async updateFiles(updates: {filePath: string; text: string; version: number}[]) { - for (const update of updates) { - if (this.connection) { - const uri = await toUri(update.filePath); - await this.connection.sendNotification('textDocument/didChange', { - textDocument: {uri, version: update.version}, - contentChanges: [{text: update.text}], - }); - } - } - } - async closeFile(filePath: string) { const cleanPath = filePath.startsWith('file://') ? fileURLToPath(filePath) : filePath; this.openedFiles = this.openedFiles.filter((u) => u !== cleanPath && u !== filePath); @@ -582,40 +553,6 @@ export function expectDoesNotContain( } } -export function expectReplacementText( - completions: CompletionList | null | undefined, - text: string, - replacementText: string, -) { - if (!completions) { - return; - } - - for (const entry of completions.items) { - expect(entry.textEdit).toBeDefined(); - if (entry.textEdit && 'range' in entry.textEdit) { - // Check range replacement - expect(entry.textEdit.newText).toBe(replacementText); - } - } -} - -export function expectContainInsertText( - completions: CompletionList | null | undefined, - kind: CompletionItemKind | string, - insertTexts: string[], -) { - expect(completions).toBeDefined(); - for (const insertText of insertTexts) { - const found = completions!.items.some( - (e) => (e.insertText === insertText || e.label === insertText) && matchesKind(e.kind, kind), - ); - expect(found) - .withContext(`Expected completions to contain insertText "${insertText}" of kind "${kind}"`) - .toBe(true); - } -} - export function expectContainInsertTextWithSnippet( completions: CompletionList | null | undefined, kind: CompletionItemKind | string,