Skip to content

Commit b2fd11e

Browse files
authored
feat(server): provide folding ranges for inline templates (#1779)
* test(server): Remove spec for view engine, which is no longer supported To support legacy view engine, we install an old version of the language server into the vsix. * build: remove unused esbuild.js The esbuild configuration is now managed in the BUILD.bazel rules. * feat(server): provide folding ranges for inline templates Following the embedded language support documentation, this commit provides folding ranges for inline templates in typescript files. This feature is provided in the language server so other editors that use the @angular/language-server package can make use of the feature as well. https://code.visualstudio.com/api/language-extensions/embedded-languages fixes #852 * fixup! feat(server): provide folding ranges for inline templates * fixup! feat(server): provide folding ranges for inline templates * fixup! feat(server): provide folding ranges for inline templates
1 parent f5f7bb1 commit b2fd11e

File tree

14 files changed

+265
-224
lines changed

14 files changed

+265
-224
lines changed

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ npm_package(
5454
":node_modules/semver",
5555
":node_modules/typescript",
5656
":node_modules/vscode-jsonrpc",
57+
":node_modules/vscode-html-languageservice",
5758
":node_modules/vscode-languageclient",
5859
":node_modules/vscode-languageserver-protocol",
5960
":node_modules/vscode-languageserver-types",

client/src/client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,15 @@ export class AngularLanguageClient implements vscode.Disposable {
151151
}
152152

153153
return angularCompletionsPromise;
154-
}
154+
},
155+
provideFoldingRanges: async (
156+
document: vscode.TextDocument, context: vscode.FoldingContext,
157+
token: vscode.CancellationToken, next) => {
158+
if (!(await this.isInAngularProject(document)) || document.languageId !== 'typescript') {
159+
return null;
160+
}
161+
return next(document, context, token);
162+
},
155163
}
156164
};
157165
}

esbuild.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

integration/lsp/ivy_spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,38 @@ describe('Angular Ivy language server', () => {
181181
expect(targetUri).toContain('libs/post/src/lib/post.component.ts');
182182
});
183183

184+
it('provides folding ranges for inline templates', async () => {
185+
openTextDocument(client, APP_COMPONENT, `
186+
import {Component, EventEmitter, Input, Output} from '@angular/core';
187+
188+
@Component({
189+
selector: 'my-app',
190+
template: \`
191+
<div>
192+
<span>
193+
Hello {{name}}
194+
</span>
195+
</div>\`,
196+
})
197+
export class AppComponent {
198+
name = 'Angular';
199+
@Input() appInput = '';
200+
@Output() appOutput = new EventEmitter<string>();
201+
}`);
202+
const languageServiceEnabled = await waitForNgcc(client);
203+
expect(languageServiceEnabled).toBeTrue();
204+
const response = await client.sendRequest(lsp.FoldingRangeRequest.type, {
205+
textDocument: {
206+
uri: APP_COMPONENT_URI,
207+
},
208+
}) as lsp.FoldingRange[];
209+
expect(Array.isArray(response)).toBe(true);
210+
// 1 folding range for the div, 1 for the span
211+
expect(response.length).toEqual(2);
212+
expect(response).toContain({startLine: 6, endLine: 9});
213+
expect(response).toContain({startLine: 7, endLine: 8});
214+
});
215+
184216
describe('signature help', () => {
185217
it('should show signature help for an empty call', async () => {
186218
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {

integration/lsp/viewengine_spec.ts

Lines changed: 0 additions & 144 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"main": "./dist/client/src/extension",
202202
"scripts": {
203203
"ng-dev": "cross-env TS_NODE_PROJECT=$PWD/.ng-dev/tsconfig.json TS_NODE_TRANSPILE_ONLY=1 node --no-warnings --loader ts-node/esm node_modules/@angular/dev-infra-private/ng-dev/bundles/cli.mjs",
204-
"compile": "tsc -b && node esbuild.js",
204+
"compile": "tsc -b && yarn bazel build :npm",
205205
"compile:test": "tsc -b test.tsconfig.json",
206206
"compile:integration": "tsc -b integration && yarn --cwd integration/project build",
207207
"compile:syntaxes-test": "tsc -b syntaxes/test",
@@ -248,6 +248,7 @@
248248
"tslint": "6.1.3",
249249
"tslint-eslint-rules": "5.4.0",
250250
"vsce": "1.100.1",
251+
"vscode-html-languageservice": "^5.0.2",
251252
"vscode-languageserver-protocol": "3.16.0",
252253
"vscode-languageserver-textdocument": "1.0.7",
253254
"vscode-test": "1.6.1",
@@ -257,4 +258,4 @@
257258
"type": "git",
258259
"url": "https://github.com/angular/vscode-ng-language-service"
259260
}
260-
}
261+
}

server/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ esbuild(
5353
"vscode-languageserver",
5454
"vscode-uri",
5555
"vscode-jsonrpc",
56+
"vscode-languageserver-textdocument",
57+
"vscode-html-languageservice",
5658
],
5759
config = "esbuild.mjs",
5860
# Do not enable minification. It seems to break the extension on Windows (with WSL). See #1198.

server/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
},
1717
"dependencies": {
1818
"@angular/language-service": "15.0.0-next.0",
19+
"vscode-html-languageservice": "^5.0.2",
1920
"vscode-jsonrpc": "6.0.0",
2021
"vscode-languageserver": "7.0.0",
22+
"vscode-languageserver-textdocument": "^1.0.7",
2123
"vscode-uri": "3.0.3"
2224
},
2325
"publishConfig": {
2426
"registry": "https://wombat-dressing-room.appspot.com"
2527
}
26-
}
28+
}

server/src/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ ts_project(
1111
"//:node_modules/@angular/language-service",
1212
"//:node_modules/@types/node",
1313
"//:node_modules/typescript",
14+
"//:node_modules/vscode-html-languageservice",
1415
"//:node_modules/vscode-languageserver",
16+
"//:node_modules/vscode-languageserver-textdocument",
1517
"//:node_modules/vscode-uri",
1618
"//common",
1719
],

server/src/banner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const originalRequire = require;
1818
* compile the server and add this banner to the top of the compilation so any place
1919
* in the server code that uses `require` will get routed through this override.
2020
*
21-
* Refer also to `esbuild.js`, the `bannerConfig` which overrides the `require` using
22-
* the `footer` option, and the `serverConfig` which provides the banner code at the top
23-
* of the server output using the `banner` option.
21+
* Refer also to `esbuild` rules in the server package, the `bannerConfig` which overrides the
22+
* `require` using the `footer` option, and the `serverConfig` which provides the banner code at the
23+
* top of the server output using the `banner` option.
2424
*
2525
* @param moduleName The module to resolve
2626
* @returns

0 commit comments

Comments
 (0)