Skip to content

Commit a291516

Browse files
authored
feat(server): Definitions for sources compiled with declarationMap … (#1601)
* feat(server): Definitions for sources compiled with `declarationMap` go to original source The TypeScript language service has the ability to map definitions back to their original source when the library code was compiled with `declarationMap`. However, this functionality is not exposed as public API. As a result, these methods could change in the future without our knowledge. resolves #1588 * fixup! feat(server): Definitions for sources compiled with `declarationMap` go to original source
1 parent 3bd10ac commit a291516

File tree

14 files changed

+1563
-20
lines changed

14 files changed

+1563
-20
lines changed

integration/lsp/ivy_spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,28 @@ describe('Angular Ivy language server', () => {
160160
});
161161
});
162162

163+
it('goes to definition of original source when compiled with source maps', async () => {
164+
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {
165+
textDocument: {
166+
uri: FOO_TEMPLATE_URI,
167+
languageId: 'html',
168+
version: 1,
169+
text: `<lib-post></lib-post>`,
170+
},
171+
});
172+
const languageServiceEnabled = await waitForNgcc(client);
173+
expect(languageServiceEnabled).toBeTrue();
174+
const response = await client.sendRequest(lsp.DefinitionRequest.type, {
175+
textDocument: {
176+
uri: FOO_TEMPLATE_URI,
177+
},
178+
position: {line: 0, character: 1},
179+
}) as lsp.LocationLink[];
180+
expect(Array.isArray(response)).toBe(true);
181+
const {targetUri} = response[0];
182+
expect(targetUri).toContain('libs/post/src/lib/post.component.ts');
183+
});
184+
163185
describe('signature help', () => {
164186
it('should show signature help for an empty call', async () => {
165187
client.sendNotification(lsp.DidOpenTextDocumentNotification.type, {

integration/project/app/app.module.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import { CommonModule } from '@angular/common';
2-
import { NgModule } from '@angular/core';
3-
import { AppComponent } from './app.component';
4-
import { FooComponent } from './foo.component';
1+
import {CommonModule} from '@angular/common';
2+
import {NgModule} from '@angular/core';
3+
import {PostModule} from 'post';
4+
5+
import {AppComponent} from './app.component';
6+
import {FooComponent} from './foo.component';
57

68
@NgModule({
7-
imports: [
9+
imports: [
810
CommonModule,
11+
PostModule,
912
],
1013
declarations: [
1114
AppComponent,
1215
FooComponent,
1316
],
14-
bootstrap: [ AppComponent ]
17+
bootstrap: [AppComponent]
1518
})
16-
export class AppModule { }
19+
export class AppModule {
20+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{title | uppercase}}
22
<span class="subtitle">
33
subtitle
4-
</span>
4+
</span>
5+
<lib-post></lib-post>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "../../dist/post",
4+
"lib": {
5+
"entryFile": "src/index.ts"
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "post",
3+
"version": "0.0.1",
4+
"peerDependencies": {
5+
"@angular/core": "^13.0.0"
6+
},
7+
"dependencies": {
8+
"tslib": "^2.3.0"
9+
}
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/post.component';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {Component, NgModule} from '@angular/core';
2+
3+
@Component({
4+
selector: 'lib-post',
5+
template: '{{random}}',
6+
})
7+
export class PostComponent {
8+
random = Math.random();
9+
}
10+
11+
@NgModule({
12+
declarations: [PostComponent],
13+
exports: [PostComponent],
14+
})
15+
export class PostModule {
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"files": [],
4+
"include": [
5+
"**/*.ts"
6+
],
7+
"compilerOptions": {
8+
"outDir": "../../tsc-dist/post",
9+
"rootDir": ".",
10+
"declaration": true,
11+
"declarationMap": true,
12+
"inlineSources": true,
13+
"sourceMap": true,
14+
"types": []
15+
},
16+
}

integration/project/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,12 @@
88
"@angular/core": "13.0.0-rc.3",
99
"rxjs": "6.6.7",
1010
"zone.js": "0.11.4"
11+
},
12+
"devDependencies": {
13+
"ng-packagr": "^13.2.0",
14+
"typescript": "~4.4.3"
15+
},
16+
"scripts": {
17+
"build": "ng-packagr -p libs/post/ng-package.json -c libs/post/tsconfig.json"
1118
}
12-
}
19+
}

integration/project/tsconfig.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
"strict": true,
77
"typeRoots": [
88
"node_modules/@types"
9-
]
9+
],
10+
"baseUrl": ".",
11+
"paths": {
12+
"post": [
13+
"dist/post"
14+
]
15+
}
1016
},
1117
"angularCompilerOptions": {
1218
"strictTemplates": true,
1319
"strictInjectionParameters": true
1420
}
15-
}
21+
}

0 commit comments

Comments
 (0)