feat(language-service): add definitions for styleUrls (#32464)

Adds support for `styleUrls` definitions in the same way `templateUrl`
definitions are provided; clicking on styleUrl will take a user to the
respective file.

Unifies some code in determining a URL definition. We first check if a
url is a `templateUrl`; if it's not, we check that it's a `styleUrl` or
return no definitions.

PR Close #32464
This commit is contained in:
ayazhafiz
2019-09-01 09:56:29 -05:00
committed by Matias Niemelä
parent c3a1ef219e
commit a391aebbcf
7 changed files with 144 additions and 40 deletions

View File

@ -0,0 +1,32 @@
{
"seq": 0,
"type": "response",
"command": "definitionAndBoundSpan",
"request_seq": 3,
"success": true,
"body": {
"definitions": [
{
"file": "${PWD}/project/app/style.css",
"start": {
"line": 1,
"offset": 1
},
"end": {
"line": 1,
"offset": 1
}
}
],
"textSpan": {
"start": {
"line": 6,
"offset": 16
},
"end": {
"line": 6,
"offset": 27
}
}
}
}

View File

@ -0,0 +1,4 @@
body,
html {
width: 100%;
}

View File

@ -3,5 +3,6 @@ import { Component } from '@angular/core';
@Component({
selector: 'my-widget',
templateUrl: './widget.component.html',
styleUrls: ['./style.css'],
})
export class WidgetComponent { name = 'Angular'; }

View File

@ -5,7 +5,7 @@ import {Client} from './tsclient';
describe('Angular Language Service', () => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; /* 10 seconds */
const PWD = process.env.PWD !;
const PWD = process.env.PWD!;
const SERVER_PATH = './node_modules/typescript/lib/tsserver.js';
let server: ChildProcess;
let client: Client;
@ -27,14 +27,14 @@ describe('Angular Language Service', () => {
client.listen();
});
afterEach(async() => {
afterEach(async () => {
client.sendRequest('exit', {});
// Give server process some time to flush all messages
await new Promise((resolve) => setTimeout(resolve, 1000));
});
it('should be launched as tsserver plugin', async() => {
it('should be launched as tsserver plugin', async () => {
let response = await client.sendRequest('configure', {
hostInfo: 'vscode',
});
@ -60,7 +60,7 @@ describe('Angular Language Service', () => {
client.sendRequest('geterr', {delay: 0, files: [`${PWD}/project/app/app.module.ts`]});
});
it('should perform completions', async() => {
it('should perform completions', async () => {
await client.sendRequest('configure', {
hostInfo: 'vscode',
});
@ -98,7 +98,7 @@ describe('Angular Language Service', () => {
expect(response).toMatchGolden('completionInfo.json');
});
it('should perform quickinfo', async() => {
it('should perform quickinfo', async () => {
client.sendRequest('open', {
file: `${PWD}/project/app/app.component.ts`,
});
@ -118,7 +118,7 @@ describe('Angular Language Service', () => {
expect(resp2).toMatchGolden('quickinfo.json');
});
it('should perform definition', async() => {
it('should perform definition', async () => {
client.sendRequest('open', {
file: `${PWD}/project/app/app.component.ts`,
});
@ -138,7 +138,7 @@ describe('Angular Language Service', () => {
expect(resp2).toMatchGolden('definition.json');
});
it('should perform definitionAndBoundSpan', async() => {
it('should perform definitionAndBoundSpan', async () => {
client.sendRequest('open', {
file: `${PWD}/project/app/app.component.ts`,
});
@ -158,7 +158,7 @@ describe('Angular Language Service', () => {
expect(resp2).toMatchGolden('definitionAndBoundSpan.json');
});
it('should perform definitionAndBoundSpan for template URLs', async() => {
it('should perform definitionAndBoundSpan for template URLs', async () => {
client.sendRequest('open', {
file: `${PWD}/project/app/widget.component.ts`,
});
@ -177,4 +177,27 @@ describe('Angular Language Service', () => {
});
expect(resp2).toMatchGolden('templateUrlDefinition.json');
});
it('should perform definitionAndBoundSpan for style URLs', async () => {
client.sendRequest('open', {
file: `${PWD}/project/app/widget.component.ts`,
});
client.sendRequest('open', {
file: `${PWD}/project/app/style.css`,
});
const resp1 = await client.sendRequest('reload', {
file: `${PWD}/project/app/widget.component.ts`,
tmpFile: `${PWD}/project/app/widget.component.ts`,
}) as any;
expect(resp1.command).toBe('reload');
expect(resp1.success).toBe(true);
const resp2 = await client.sendRequest('definitionAndBoundSpan', {
file: `${PWD}/project/app/widget.component.ts`,
line: 6,
offset: 18,
});
expect(resp2).toMatchGolden('styleUrlsDefinition.json');
});
});