Skip to content

Commit 2bf02b0

Browse files
committed
Cleanup
1 parent 72caed7 commit 2bf02b0

File tree

7 files changed

+56
-28
lines changed

7 files changed

+56
-28
lines changed

scripts/buildProtocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ function generateProtocolFile(protocolTs: string, typeScriptServicesDts: string)
167167
const sanityCheckProgram = getProgramWithProtocolText(protocolDts, /*includeTypeScriptServices*/ false);
168168
const diagnostics = [...sanityCheckProgram.getSyntacticDiagnostics(), ...sanityCheckProgram.getSemanticDiagnostics(), ...sanityCheckProgram.getGlobalDiagnostics()];
169169
if (diagnostics.length) {
170-
// const flattenedDiagnostics = diagnostics.map(d => ts.flattenDiagnosticMessageText(d.messageText, "\n") + ' at ' + d.file.fileName + ' line ' + d.start).join("\n");
171-
// throw new Error(`Unexpected errors during sanity check: ${flattenedDiagnostics}`);
170+
const flattenedDiagnostics = diagnostics.map(d => ts.flattenDiagnosticMessageText(d.messageText, "\n") + ' at ' + d.file.fileName + ' line ' + d.start).join("\n");
171+
throw new Error(`Unexpected errors during sanity check: ${flattenedDiagnostics}`);
172172
}
173173
return protocolDts;
174174
}

src/compiler/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,7 +3245,7 @@ namespace ts {
32453245
/* @internal */
32463246
export interface CommandLineOptionBase {
32473247
name: string;
3248-
type: "string" | "number" | "boolean" | "object" | "json" | "list" | Map<number | string>; // a value of a primitive type, or an object literal mapping named values to actual values
3248+
type: "string" | "number" | "boolean" | "object" | "list" | Map<number | string>; // a value of a primitive type, or an object literal mapping named values to actual values
32493249
isFilePath?: boolean; // True if option value is a path or fileName
32503250
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'
32513251
description?: DiagnosticMessage; // The message describing what the command line switch does
@@ -3266,13 +3266,13 @@ namespace ts {
32663266

32673267
/* @internal */
32683268
export interface TsConfigOnlyOption extends CommandLineOptionBase {
3269-
type: "object" | "json";
3269+
type: "object";
32703270
}
32713271

32723272
/* @internal */
32733273
export interface CommandLineOptionOfListType extends CommandLineOptionBase {
32743274
type: "list";
3275-
element: CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType;
3275+
element: CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType | TsConfigOnlyOption;
32763276
}
32773277

32783278
/* @internal */

src/harness/fourslash.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,40 @@ namespace FourSlash {
245245
}
246246
}
247247

248+
static mockResolveModule(moduleName: string, _initialDir: string, _host: ts.server.ServerHost, log: (message: string) => void): ts.server.PluginModule {
249+
log(`Mock resolving ${moduleName}`);
250+
return {
251+
create(_proj: any, langSvc: any, _config: any) {
252+
// tslint:disable-next-line:no-null-keyword
253+
const proxy = Object.create(null);
254+
for (const k of Object.keys(langSvc)) {
255+
proxy[k] = function () {
256+
return langSvc[k].apply(langSvc, arguments);
257+
};
258+
}
259+
260+
proxy.getQuickInfoAtPosition = function () {
261+
const parts = langSvc.getQuickInfoAtPosition.apply(langSvc, arguments);
262+
if (parts.displayParts.length > 0) {
263+
parts.displayParts[0].text = "Proxied";
264+
}
265+
parts.displayParts.push({ text: "Check", kind: "punctuation" });
266+
return parts;
267+
};
268+
269+
return proxy;
270+
}
271+
};
272+
}
273+
248274
constructor(private basePath: string, private testType: FourSlashTestType, public testData: FourSlashData) {
249275
// Create a new Services Adapter
250276
this.cancellationToken = new TestCancellationToken();
251277
let compilationOptions = convertGlobalOptionsToCompilerOptions(this.testData.globalOptions);
252278
compilationOptions.skipDefaultLibCheck = true;
253279

280+
ts.server.Project.resolveModule = TestState.mockResolveModule;
281+
254282
// Initialize the language service with all the scripts
255283
let startResolveFileRef: FourSlashFile;
256284

@@ -480,7 +508,7 @@ namespace FourSlash {
480508
endPos = endMarker.position;
481509
}
482510

483-
errors.forEach(function(error: ts.Diagnostic) {
511+
errors.forEach(function (error: ts.Diagnostic) {
484512
if (predicate(error.start, error.start + error.length, startPos, endPos)) {
485513
exists = true;
486514
}
@@ -497,7 +525,7 @@ namespace FourSlash {
497525
Harness.IO.log("Unexpected error(s) found. Error list is:");
498526
}
499527

500-
errors.forEach(function(error: ts.Diagnostic) {
528+
errors.forEach(function (error: ts.Diagnostic) {
501529
Harness.IO.log(" minChar: " + error.start +
502530
", limChar: " + (error.start + error.length) +
503531
", message: " + ts.flattenDiagnosticMessageText(error.messageText, Harness.IO.newLine()) + "\n");

src/server/editorServices.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,6 @@ namespace ts.server {
10041004
if (!project.languageServiceEnabled) {
10051005
project.enableLanguageService();
10061006
}
1007-
10081007
this.watchConfigDirectoryForProject(project, projectOptions);
10091008
this.updateNonInferredProject(project, projectOptions.files, fileNamePropertyReader, projectOptions.compilerOptions, projectOptions.typingOptions, projectOptions.compileOnSave, configFileErrors);
10101009
}

src/server/project.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ namespace ts.server {
9090
}
9191
}
9292

93+
export interface PluginModule {
94+
create(proj: Project, languageService: LanguageService, config: any): LanguageService;
95+
}
96+
9397
export abstract class Project {
9498
private rootFiles: ScriptInfo[] = [];
9599
private rootFilesMap: FileMap<ScriptInfo> = createFileMap<ScriptInfo>();
@@ -148,20 +152,21 @@ namespace ts.server {
148152
log(`Root plugin search path is ${searchPath}`);
149153
let loaded = false;
150154
// Walk up probing node_modules paths
151-
while (!loaded && getBaseFileName(searchPath) !== '') {
152-
const probePath = combinePaths(combinePaths(searchPath, 'node_modules'), moduleName);
155+
while (!loaded && getBaseFileName(searchPath) !== "") {
156+
const probePath = combinePaths(combinePaths(searchPath, "node_modules"), moduleName);
153157
if (host.directoryExists(probePath)) {
154158
log(`Loading ${moduleName} from ${probePath}`);
155159
try {
156160
const pluginModule = require(probePath);
157161
return pluginModule;
158-
} catch (e) {
162+
}
163+
catch (e) {
159164
log(`Require failed: ${e}`);
160165
}
161166
loaded = true;
162167
}
163168
else {
164-
searchPath = normalizePath(combinePaths(searchPath, '..'));
169+
searchPath = normalizePath(combinePaths(searchPath, ".."));
165170
log(`Walking up to probe ${searchPath}`);
166171
}
167172
}
@@ -777,34 +782,35 @@ namespace ts.server {
777782
const host = this.projectService.host;
778783
const options = this.getCompilerOptions();
779784
const log = (message: string) => {
780-
console.log(message);
781785
this.projectService.logger.info(message);
782786
};
783787

784-
console.log('Enable plugins');
785-
console.log(JSON.stringify(options));
786-
787788
if (!(options.plugins && options.plugins.length)) {
788789
// No plugins
789790
return;
790791
}
791792

792-
if (typeof require === 'undefined') {
793-
this.projectService.logger.info('Plugins were requested but not running in node environment. Nothing will be loaded');
793+
if (typeof require === "undefined") {
794+
this.projectService.logger.info("Plugins were requested but not running in node environment. Nothing will be loaded");
794795
return;
795796
}
796797

797798
for (const pluginConfigEntry of options.plugins) {
798-
const searchPath = combinePaths(this.configFileName, '../node_modules');
799-
const resolvedModule = Project.resolveModule(pluginConfigEntry.name, searchPath, host, log);
799+
const searchPath = combinePaths(this.configFileName, "..");
800+
const resolvedModule = <PluginModule>Project.resolveModule(pluginConfigEntry.name, searchPath, host, log);
800801
if (resolvedModule) {
801802
this.enableProxy(resolvedModule, pluginConfigEntry);
802803
}
803804
}
804805
}
805806

806-
private enableProxy(pluginModule: any, configEntry: PluginImport) {
807-
this.languageService = pluginModule.create(this, this.languageService, configEntry);
807+
private enableProxy(pluginModule: PluginModule, configEntry: PluginImport) {
808+
try {
809+
this.languageService = pluginModule.create(this, this.languageService, configEntry);
810+
}
811+
catch (e) {
812+
this.projectService.logger.info(`Plugin activation failed: ${e}`);
813+
}
808814
}
809815

810816
getProjectRootPath() {

src/server/utilities.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,6 @@ namespace ts.server {
236236
compilerOptions?: CompilerOptions;
237237
typingOptions?: TypingOptions;
238238
compileOnSave?: boolean;
239-
240-
/**
241-
* Additional behavior
242-
*/
243-
"ng-templates"?: string[];
244239
}
245240

246241
export function isInferredProjectName(name: string) {

tests/cases/fourslash/server/ngProxy1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
////
1717

1818
goTo.marker();
19-
debug.printCurrentQuickInfo();
19+
verify.quickInfoIs('Proxied x: number[]Check');

0 commit comments

Comments
 (0)