Skip to content

Commit

Permalink
Change to object
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanCavanaugh committed Nov 22, 2016
1 parent 2145545 commit d0f3dc7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@ namespace FourSlash {
static mockResolveModule(moduleName: string, _initialDir: string, _host: ts.server.ServerHost, log: (message: string) => void): ts.server.PluginModule {
log(`Mock resolving ${moduleName}`);
return {
create(_proj: any, langSvc: any, _config: any) {
create(info: ts.server.PluginCreateInfo) {
// tslint:disable-next-line:no-null-keyword
const proxy = Object.create(null);
const langSvc: any = info.languageService;
for (const k of Object.keys(langSvc)) {
proxy[k] = function () {
return langSvc[k].apply(langSvc, arguments);
Expand Down
2 changes: 1 addition & 1 deletion src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2028,5 +2028,5 @@ namespace Harness {
return { unitName: libFile, content: io.readFile(libFile) };
}

if (Error) (<any>Error).stackTraceLimit = 20;
if (Error) (<any>Error).stackTraceLimit = 1;
}
30 changes: 26 additions & 4 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,16 @@ namespace ts.server {
};
}

export interface PluginCreateInfo {
project: Project;
languageService: LanguageService;
serverHost: ServerHost;
config: any;
}

export interface PluginModule {
create(proj: Project, languageService: LanguageService, config: any): LanguageService;
create(createInfo: PluginCreateInfo): LanguageService;
getExternalFiles?(proj: Project): string[];
}

export abstract class Project {
Expand Down Expand Up @@ -855,6 +863,8 @@ namespace ts.server {
private directoriesWatchedForWildcards: Map<FileWatcher>;
private typeRootsWatchers: FileWatcher[];

private plugins: PluginModule[] = [];

/** Used for configured projects which may have multiple open roots */
openRefCount = 0;

Expand Down Expand Up @@ -902,7 +912,14 @@ namespace ts.server {

private enableProxy(pluginModule: PluginModule, configEntry: PluginImport) {
try {
this.languageService = pluginModule.create(this, this.languageService, configEntry);
const info: PluginCreateInfo = {
config: configEntry,
project: this,
languageService: this.languageService,
serverHost: this.projectService.host
};
this.languageService = pluginModule.create(info);
this.plugins.push(pluginModule);
}
catch (e) {
this.projectService.logger.info(`Plugin activation failed: ${e}`);
Expand Down Expand Up @@ -930,8 +947,13 @@ namespace ts.server {
}

getExternalFiles(): string[] {
// TODO: Ask plugins for this information as well
return [];
const items: string[] = [];
for (const plugin of this.plugins) {
if (plugin.getExternalFiles) {
items.push(...plugin.getExternalFiles(this));
}
}
return items;
}

watchConfigFile(callback: (project: ConfiguredProject) => void) {
Expand Down

0 comments on commit d0f3dc7

Please sign in to comment.