Skip to content

Commit a7ae427

Browse files
committed
Language service extensions and tests
1 parent 8583037 commit a7ae427

File tree

9 files changed

+950
-23
lines changed

9 files changed

+950
-23
lines changed

src/compiler/program.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,7 @@ namespace ts {
12511251
switch (ext.kind) {
12521252
case ExtensionKind.SemanticLint:
12531253
case ExtensionKind.SyntacticLint:
1254+
case ExtensionKind.LanguageService:
12541255
if (typeof potentialExtension !== "function") {
12551256
programDiagnostics.add(createCompilerDiagnostic(
12561257
Diagnostics.Extension_0_exported_member_1_has_extension_kind_2_but_was_type_3_when_type_4_was_expected,
@@ -1262,7 +1263,13 @@ namespace ts {
12621263
));
12631264
return;
12641265
}
1265-
(ext as (SemanticLintExtension | SyntacticLintExtension)).ctor = potentialExtension;
1266+
(ext as (SemanticLintExtension | SyntacticLintExtension | LanguageServiceExtension)).ctor = potentialExtension;
1267+
break;
1268+
default:
1269+
// Include a default case which just puts the extension unchecked onto the base extension
1270+
// This can allow language service extensions to query for custom extension kinds
1271+
(ext as any).__extension = potentialExtension;
1272+
break;
12661273
}
12671274
aggregate.push(ext as Extension);
12681275
}

src/compiler/types.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,17 +2920,29 @@ namespace ts {
29202920
new (typescript: typeof ts, checker: TypeChecker, args: any): LintWalker;
29212921
}
29222922

2923+
export interface LanguageServiceHost {} // The members for these interfaces are provided in the services layer
2924+
export interface LanguageService {}
2925+
export interface LanguageServiceProvider {}
2926+
export interface DocumentRegistry {}
2927+
2928+
export interface LanguageServiceProviderStatic {
2929+
new (typescript: typeof ts, host: LanguageServiceHost, service: LanguageService, registry: DocumentRegistry, args: any): LanguageServiceProvider;
2930+
}
2931+
29232932
export namespace ExtensionKind {
29242933
export const SemanticLint: "semantic-lint" = "semantic-lint";
29252934
export type SemanticLint = "semantic-lint";
29262935
export const SyntacticLint: "syntactic-lint" = "syntactic-lint";
29272936
export type SyntacticLint = "syntactic-lint";
2937+
export const LanguageService: "language-service" = "language-service";
2938+
export type LanguageService = "language-service";
29282939
}
2929-
export type ExtensionKind = ExtensionKind.SemanticLint | ExtensionKind.SyntacticLint;
2940+
export type ExtensionKind = ExtensionKind.SemanticLint | ExtensionKind.SyntacticLint | ExtensionKind.LanguageService;
29302941

29312942
export interface ExtensionCollectionMap {
29322943
"syntactic-lint"?: SyntacticLintExtension[];
29332944
"semantic-lint"?: SemanticLintExtension[];
2945+
"language-service"?: LanguageServiceExtension[];
29342946
[index: string]: Extension[] | undefined;
29352947
}
29362948

@@ -2950,7 +2962,12 @@ namespace ts {
29502962
ctor: SemanticLintProviderStatic;
29512963
}
29522964

2953-
export type Extension = SyntacticLintExtension | SemanticLintExtension;
2965+
// @kind(ExtensionKind.LanguageService)
2966+
export interface LanguageServiceExtension extends ExtensionBase {
2967+
ctor: LanguageServiceProviderStatic;
2968+
}
2969+
2970+
export type Extension = SyntacticLintExtension | SemanticLintExtension | LanguageServiceExtension;
29542971

29552972
export interface CompilerHost extends ModuleResolutionHost {
29562973
getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile;

src/harness/external/chai.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,6 @@ declare module chai {
175175
function isOk(actual: any, message?: string): void;
176176
function isUndefined(value: any, message?: string): void;
177177
function isDefined(value: any, message?: string): void;
178+
function deepEqual(actual: any, expected: any, message?: string): void;
178179
}
179180
}

src/harness/harnessLanguageService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ namespace Harness.LanguageService {
366366
getCompilerOptionsDiagnostics(): ts.Diagnostic[] {
367367
return unwrapJSONCallResult(this.shim.getCompilerOptionsDiagnostics());
368368
}
369+
getProgramDiagnostics(): ts.Diagnostic[] {
370+
return unwrapJSONCallResult(this.shim.getProgramDiagnostics());
371+
}
369372
getSyntacticClassifications(fileName: string, span: ts.TextSpan): ts.ClassifiedSpan[] {
370373
return unwrapJSONCallResult(this.shim.getSyntacticClassifications(fileName, span.start, span.length));
371374
}

src/server/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ namespace ts.server {
395395
}
396396

397397
getCompilerOptionsDiagnostics(): Diagnostic[] {
398+
return this.getProgramDiagnostics();
399+
}
400+
401+
getProgramDiagnostics(): Diagnostic[] {
398402
throw new Error("Not Implemented Yet.");
399403
}
400404

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ namespace ts.server {
11471147
info.setFormatOptions(this.getFormatCodeOptions());
11481148
this.filenameToScriptInfo[fileName] = info;
11491149
if (!info.isOpen) {
1150-
info.fileWatcher = this.host.watchFile(fileName, _ => { this.watchedFileChanged(fileName); });
1150+
info.fileWatcher = this.host.watchFile && this.host.watchFile(fileName, _ => { this.watchedFileChanged(fileName); });
11511151
}
11521152
}
11531153
}

0 commit comments

Comments
 (0)