Skip to content

Commit 3d1cf2d

Browse files
author
Keen Yee Liau
committed
test: Add test for HTML file opened without any TS files
Now that TypeScript 3.6 has landed, the language service could correctly handle the case where HTML file is opened without any prior TS files. PR closes #411
1 parent c258f13 commit 3d1cf2d

File tree

5 files changed

+65
-4
lines changed

5 files changed

+65
-4
lines changed

integration/lsp/smoke_spec.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('Angular Language Service', () => {
8787
* process. If the parent process is not alive then the server should
8888
* exit (see exit notification) its process.
8989
*/
90-
'processId': server.pid,
90+
'processId': process.pid,
9191
'rootUri': `file://${PROJECT_PATH}`,
9292
'capabilities': {},
9393
/**
@@ -119,7 +119,7 @@ describe('Angular Language Service', () => {
119119
'id': 0,
120120
'method': 'initialize',
121121
'params': {
122-
'processId': server.pid,
122+
'processId': process.pid,
123123
'rootUri': `file://${PROJECT_PATH}`,
124124
'capabilities': {},
125125
'trace': 'off'
@@ -582,4 +582,53 @@ describe('Angular Language Service', () => {
582582
]
583583
});
584584
});
585+
586+
it('should work with external template', async () => {
587+
const r0 = await send({
588+
jsonrpc: '2.0',
589+
id: 0,
590+
method: 'initialize',
591+
params: {
592+
processId: process.pid,
593+
rootUri: `file://${PROJECT_PATH}`,
594+
capabilities: {},
595+
}
596+
});
597+
expect(r0).toBeDefined();
598+
const n0 = await send({
599+
jsonrpc: '2.0',
600+
method: 'textDocument/didOpen',
601+
params: {
602+
textDocument: {
603+
uri: `file://${PROJECT_PATH}/app/foo.component.html`,
604+
languageId: 'typescript',
605+
version: 1,
606+
}
607+
}
608+
});
609+
expect(n0).toBe(null); // no response expected from notification
610+
const r1 = await send({
611+
jsonrpc: '2.0',
612+
id: 1,
613+
method: 'textDocument/hover',
614+
params: {
615+
textDocument: {uri: `file://${PROJECT_PATH}/app/foo.component.html`},
616+
position: {line: 0, character: 3}
617+
}
618+
});
619+
expect(r1).toEqual({
620+
jsonrpc: '2.0',
621+
id: 1,
622+
result: {
623+
contents: [{
624+
language: 'typescript',
625+
value: '(property) FooComponent.title',
626+
}],
627+
range: {
628+
start: {line: 0, character: 2},
629+
end: {line: 0, character: 7},
630+
}
631+
}
632+
});
633+
});
585634
});

integration/project/app/app.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { NgModule } from '@angular/core';
22
import { AppComponent } from './app.component';
3+
import { FooComponent } from './foo.component';
34

45
@NgModule({
56
imports: [],
6-
declarations: [ AppComponent ],
7+
declarations: [
8+
AppComponent,
9+
FooComponent,
10+
],
711
bootstrap: [ AppComponent ]
812
})
913
export class AppModule { }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{title}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
templateUrl: 'foo.component.html',
5+
})
6+
export class FooComponent {
7+
title = 'Foo Component';
8+
}

server/src/session.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ export class Session {
153153
this.connection.console.error(configFileErrors.map(e => e.messageText).join('\n'));
154154
}
155155
if (!configFileName) {
156-
// TODO: This could happen if the first file opened is HTML. Fix this.
157156
this.connection.console.error(`No config file for ${filePath}`);
158157
return;
159158
}

0 commit comments

Comments
 (0)