Skip to content

Commit 2145545

Browse files
committed
Cleanup
1 parent ae9f83d commit 2145545

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
@@ -3309,7 +3309,7 @@ namespace ts {
33093309
/* @internal */
33103310
export interface CommandLineOptionBase {
33113311
name: string;
3312-
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
3312+
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
33133313
isFilePath?: boolean; // True if option value is a path or fileName
33143314
shortName?: string; // A short mnemonic for convenience - for instance, 'h' can be used in place of 'help'
33153315
description?: DiagnosticMessage; // The message describing what the command line switch does
@@ -3330,13 +3330,13 @@ namespace ts {
33303330

33313331
/* @internal */
33323332
export interface TsConfigOnlyOption extends CommandLineOptionBase {
3333-
type: "object" | "json";
3333+
type: "object";
33343334
}
33353335

33363336
/* @internal */
33373337
export interface CommandLineOptionOfListType extends CommandLineOptionBase {
33383338
type: "list";
3339-
element: CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType;
3339+
element: CommandLineOptionOfCustomType | CommandLineOptionOfPrimitiveType | TsConfigOnlyOption;
33403340
}
33413341

33423342
/* @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
@@ -1040,7 +1040,6 @@ namespace ts.server {
10401040
if (!project.languageServiceEnabled) {
10411041
project.enableLanguageService();
10421042
}
1043-
10441043
this.watchConfigDirectoryForProject(project, projectOptions);
10451044
this.updateNonInferredProject(project, projectOptions.files, fileNamePropertyReader, projectOptions.compilerOptions, projectOptions.typingOptions, projectOptions.compileOnSave, configFileErrors);
10461045
}

src/server/project.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ namespace ts.server {
171171
};
172172
}
173173

174+
export interface PluginModule {
175+
create(proj: Project, languageService: LanguageService, config: any): LanguageService;
176+
}
177+
174178
export abstract class Project {
175179
private rootFiles: ScriptInfo[] = [];
176180
private rootFilesMap: FileMap<ScriptInfo> = createFileMap<ScriptInfo>();
@@ -234,20 +238,21 @@ namespace ts.server {
234238
log(`Root plugin search path is ${searchPath}`);
235239
let loaded = false;
236240
// Walk up probing node_modules paths
237-
while (!loaded && getBaseFileName(searchPath) !== '') {
238-
const probePath = combinePaths(combinePaths(searchPath, 'node_modules'), moduleName);
241+
while (!loaded && getBaseFileName(searchPath) !== "") {
242+
const probePath = combinePaths(combinePaths(searchPath, "node_modules"), moduleName);
239243
if (host.directoryExists(probePath)) {
240244
log(`Loading ${moduleName} from ${probePath}`);
241245
try {
242246
const pluginModule = require(probePath);
243247
return pluginModule;
244-
} catch (e) {
248+
}
249+
catch (e) {
245250
log(`Require failed: ${e}`);
246251
}
247252
loaded = true;
248253
}
249254
else {
250-
searchPath = normalizePath(combinePaths(searchPath, '..'));
255+
searchPath = normalizePath(combinePaths(searchPath, ".."));
251256
log(`Walking up to probe ${searchPath}`);
252257
}
253258
}
@@ -873,34 +878,35 @@ namespace ts.server {
873878
const host = this.projectService.host;
874879
const options = this.getCompilerOptions();
875880
const log = (message: string) => {
876-
console.log(message);
877881
this.projectService.logger.info(message);
878882
};
879883

880-
console.log('Enable plugins');
881-
console.log(JSON.stringify(options));
882-
883884
if (!(options.plugins && options.plugins.length)) {
884885
// No plugins
885886
return;
886887
}
887888

888-
if (typeof require === 'undefined') {
889-
this.projectService.logger.info('Plugins were requested but not running in node environment. Nothing will be loaded');
889+
if (typeof require === "undefined") {
890+
this.projectService.logger.info("Plugins were requested but not running in node environment. Nothing will be loaded");
890891
return;
891892
}
892893

893894
for (const pluginConfigEntry of options.plugins) {
894-
const searchPath = combinePaths(this.configFileName, '../node_modules');
895-
const resolvedModule = Project.resolveModule(pluginConfigEntry.name, searchPath, host, log);
895+
const searchPath = combinePaths(this.configFileName, "..");
896+
const resolvedModule = <PluginModule>Project.resolveModule(pluginConfigEntry.name, searchPath, host, log);
896897
if (resolvedModule) {
897898
this.enableProxy(resolvedModule, pluginConfigEntry);
898899
}
899900
}
900901
}
901902

902-
private enableProxy(pluginModule: any, configEntry: PluginImport) {
903-
this.languageService = pluginModule.create(this, this.languageService, configEntry);
903+
private enableProxy(pluginModule: PluginModule, configEntry: PluginImport) {
904+
try {
905+
this.languageService = pluginModule.create(this, this.languageService, configEntry);
906+
}
907+
catch (e) {
908+
this.projectService.logger.info(`Plugin activation failed: ${e}`);
909+
}
904910
}
905911

906912
getProjectRootPath() {

src/server/utilities.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@ namespace ts.server {
173173
compilerOptions?: CompilerOptions;
174174
typingOptions?: TypingOptions;
175175
compileOnSave?: boolean;
176-
177-
/**
178-
* Additional behavior
179-
*/
180-
"ng-templates"?: string[];
181176
}
182177

183178
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)