Skip to content

Commit fee9166

Browse files
kyliauKeen Yee Liau
authored and
Keen Yee Liau
committed
refactor: move notification types to common package
Currently, the notification types in `protocol.ts` are duplicated in both `client` and `server`. This commit consolidates them into `common` and create a project reference. This is done in preparation for the ngcc work, which will add more notification types. With this change, `client` and `server` now have to depend on the `.d.ts` output of `common`. Although this is the right way to organize the code, it introduces two unfortunate side effects: 1. `client` and `server` now have to import from `common/out`, since that's the output directory where the declaration files are emitted. 2. users who clone this repo will have to run `yarn compile` to build the repo before they can navigate the project in their editor. (1) does not look "nice", but it offers a straight-forward way without too drastic changes to the build workflow. While (2) this is not ideal, it is the correct way of using project references according to the TS [documentation](https://www.typescriptlang.org/docs/handbook/project-references.html#caveats-for-project-references). > Because dependent projects make use of .d.ts files that are built from their > dependencies, you’ll either have to check in certain build outputs or build > a project after cloning it before you can navigate the project in an editor > without seeing spurious errors. TypeScript does plan to improve the ergonomics of project references in the future. > We’re working on a behind-the-scenes .d.ts generation process that should be > able to mitigate this, but for now we recommend informing developers that > they should build after cloning.
1 parent 2a6ecea commit fee9166

File tree

10 files changed

+41
-19
lines changed

10 files changed

+41
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
node_modules
55
client/node_modules/
66
client/out/
7+
common/out
78
server/node_modules/
89
server/out
910
integration/out

DEVELOPER.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## Navigating Projects in IDE
2+
3+
This repository contains multiple TypeScript projects, each with its own `tsconfig.json`.
4+
TypeScript's [project references](https://www.typescriptlang.org/docs/handbook/project-references.html) are used to handle the builds.
5+
As a result, some projects depend on the `.d.ts` output of their dependencies, like `client`
6+
and `server` depend on `common`. In order to navigate the projects in your IDE,
7+
you need to first build them by running
8+
```shell
9+
yarn compile
10+
```
11+
12+
If you'd like to force a clean build, you can delete the existing build artifacts
13+
by running
14+
```shell
15+
./scripts/build.sh
16+
```
17+
118
## Formatting source code
219

320
This repository uses the [NPM distribution](https://www.npmjs.com/package/clang-format) of

client/src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import * as path from 'path';
1111
import * as vscode from 'vscode';
1212
import * as lsp from 'vscode-languageclient';
1313

14+
import {projectLoadingNotification} from '../../common/out/notifications';
15+
1416
import {registerCommands} from './commands';
15-
import {projectLoadingNotification} from './protocol';
1617

1718
export function activate(context: vscode.ExtensionContext) {
1819
// If the extension is launched in debug mode then the debug server options are used

client/src/protocol.ts

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

client/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"compilerOptions": {
44
"outDir": "out"
55
},
6+
"references": [
7+
{"path": "../common"}
8+
],
69
"include": ["src"],
710
"exclude": ["node_modules"]
811
}

server/src/protocol.ts renamed to common/notifications.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {NotificationType0} from 'vscode-languageserver';
9+
import {NotificationType0} from 'vscode-jsonrpc';
1010

1111
export const projectLoadingNotification = {
12-
start: new NotificationType0<string>('angular-language-service/projectLoadingStart'),
13-
finish: new NotificationType0<string>('angular-language-service/projectLoadingFinish')
12+
start: new NotificationType0('angular/projectLoadingStart'),
13+
finish: new NotificationType0('angular/projectLoadingFinish')
1414
};

common/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"composite": true,
5+
"outDir": "out",
6+
"rootDir": ".",
7+
},
8+
"include": ["*.ts"]
9+
}

scripts/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set -ex -o pipefail
66
shopt -s extglob
77

88
# Clean up from last build
9+
rm -rf common/out
910
rm -rf client/out
1011
rm -rf server/out
1112
rm -rf syntaxes/out

server/src/session.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import * as ts from 'typescript/lib/tsserverlibrary';
1010
import * as lsp from 'vscode-languageserver';
1111

12+
import {projectLoadingNotification} from '../../common/out/notifications';
13+
1214
import {tsCompletionEntryToLspCompletionItem} from './completion';
1315
import {tsDiagnosticToLspDiagnostic} from './diagnostic';
1416
import {Logger} from './logger';
15-
import {projectLoadingNotification} from './protocol';
1617
import {ServerHost} from './server_host';
1718
import {filePathToUri, lspPositionToTsPosition, lspRangeToTsPositions, tsTextSpanToLspRange, uriToFilePath} from './utils';
1819

server/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"outDir": "out",
66
"rootDir": "src"
77
},
8+
"references": [
9+
{"path": "../common"}
10+
],
811
"include": ["src/*.ts"],
912
"exclude": [
1013
"src/banner.ts",

0 commit comments

Comments
 (0)