-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TSS plugin] How to dynamically load d.ts file #40503
Comments
@mjbvz If enabled I want to load Here is what I've been tried: |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
I stumbled across this bug because I was looking to do exactly the same thing so I thought I'd share my solution for posterity 😄 I figured out that calling Put together into a simple plugin implementation: import typescript from "typescript/lib/tsserverlibrary";
module.exports = function init(): typescript.server.PluginModule {
let path: string | null = null;
let typescriptProject: typescript.server.Project;
return {
create(
createInfo: typescript.server.PluginCreateInfo
): typescript.LanguageService {
const { languageService, languageServiceHost, project, config } = createInfo;
typescriptProject = project;
// Read the initial config
path = config.path;
// Bind the original implementation so it can be called from
// the overriding implementation
const getScriptFileNames = languageServiceHost.getScriptFileNames.bind(
languageServiceHost
);
languageServiceHost.getScriptFileNames = () => {
const scriptFileNames = getScriptFileNames();
if (!!path) {
scriptFileNames.push(path);
}
return scriptFileNames;
};
return languageService;
},
onConfigurationChanged(config: { path: string | null }) {
if (config.path !== path) {
path = config.path;
typescriptProject.markAsDirty();
}
}
};
}; Edit: Edited to read the initial config from |
I want to turn ON/OFF tss plugin by changing enable field in config, and when I need to add/remove d.ts files, I encountered this problem
the
this.configurationManager.getPluginConfig()?.enable
turned to true, deno.d.ts added to scriptFileNames, but still don't get the types declared in deno.d.tsI tried add this piece of code from #11810 (comment)
didn't work either
tsserver.log
The text was updated successfully, but these errors were encountered: