Skip to content
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

[TS] Accept all language service parameters #2582

Closed
Andarist opened this issue Jul 19, 2021 · 5 comments · May be fixed by #4414
Closed

[TS] Accept all language service parameters #2582

Andarist opened this issue Jul 19, 2021 · 5 comments · May be fixed by #4414
Labels
feature-request Request for new features or functionality

Comments

@Andarist
Copy link

Currently, most of the languageService methods are capped to certain arguments. For example, getCompletionsAtPosition only accepts 2 arguments, while the underlying service, in fact, accepts 3 arguments
https://github.com/microsoft/monaco-typescript/blob/17582eaec0872b9a311ec0dee2853e4fc6ba6cf2/src/tsWorker.ts#L235-L243

The same applies to other methods such as getCompletionEntryDetails which got capped to 3 arguments (and it accepts 7!).

I understand that allowing those arguments might require some changes in the languageFeatures and maybe in other files too. However, allowing this would make Monaco editor more robust and would unlock some new possibilities for integrators.

Context

I've wanted to enable auto-imports and I've managed to hack my way around by overriding getCompletionsAtPosition and getCompletionEntryDetails using customWorkerPath and patching the CompletionItemProvider/SuggestAdapter. I had to figure out a lot to do so though and this functionality could be enabled as easily as by calling getCompletionsAtPosition with includeCompletionsForModuleExports: true.

I understand that Monaco's goal is to support single-file editors but we can still "install" external modules with addExtraLib and so on so allowing auto-imports to work with those would be awesome. Since TS playground implements "type acquisition", this could nicely enhance the user experience in that playground as well (cc @orta). So I wouldn't say that this feature requires is special to me by any means.

@hediet hediet added the feature-request Request for new features or functionality label Jul 19, 2021
@hediet
Copy link
Member

hediet commented Jul 19, 2021

If @orta has nothing against it, I think this feature is a nice candidate for being contributed by the community.
If you submit a PR, I'd be more than happy to help you getting it merged!

@Andarist
Copy link
Author

I could take a stab at it - since I've already gone into the rabbit hole of figuring some of this stuff for hacking purposes.

There are some things that I still don't get and could use some clarification on them before I start coding things. Could the TS language stuff be unified more with what is implemented in the VScode repository? I went spelunking into both repositories (VScode and monaco-typescript), trying to figure out how they relate, on what data types they operate and how do they implement certain things. The overlap is big but so is the divergence between them. Is this mostly a historical reason? And VScode having to handle compatibility with all (most?) TS versions? Is there anything else at play here?

Any particular gotchas that you could think of at this stage already? Something I should be aware of? Is there any test suite validating the functionality beyond what can be found here and in the monaco-typescript repository? In those two there are not a lot of tests so I'm a little bit worried that I could unintentionally break some stuff due to lack of experience with those projects.

@orta
Copy link
Contributor

orta commented Jul 19, 2021

Both monaco-typescript and typescript-languge-features (vscode) are two completely separate implementations of a binding for a TS TSServer to the Monaco or VS Code APIs. They both have overlap but generally the fancy features get shipped to vscode as the TS + VS team build out a feature and then if it makes sense for web I (or a community member) sends a PR to monaco-typescript

There's probably only 2 params because that's how many params were on that function back when the feature was added, monaco-typescript is probably just ignoring all the newer params. I don't think there's a systemic constraint. You're welcome to add it 👍🏻

@Andarist
Copy link
Author

From what I've seen VScode is currently implementing completionItemProvider using the TSServer API instead of the Language Service API. Would it be possible to rewrite it to the latter (I could potentially try to dig into this)? That way rewriting the one in the monaco-typescript would get easier, and any future syncs would also be easier. I know that VScode has to support more than a single TS version so maybe there is a reason why this has not been done yet - or is it maybe just a legacy issue at this point in time?

Either way - I would love to contribute this to monaco-typescript but the docs are very sparse about a lot of things. Would anybody here be up for providing some mentoring help if I stumble upon issues that I wouldn't know how to resolve?

For instance, at the moment, in my monkey-patched "fork" I had to:

  • store access to the model so it would be used within resolveCompletionItem because this function doesn't receive it as an argument. The model was needed for me to convert the retrieved textChanges to the additionalTextEdits (had to convert a text span to a Range)
  • replace resolved node_modules paths with module names because the tryGetModuleNameAsNodeModule relies on the fs calls whereas the fs mock is not provided to TypeScript by default.

@hediet
Copy link
Member

hediet commented Mar 8, 2023

We closed this issue because we don't plan to address it in the foreseeable future. If you disagree and feel that this issue is crucial: we are happy to listen and to reconsider.

If you wonder what we are up to, please see our roadmap and issue reporting guidelines.

Thanks for your understanding, and happy coding!

@hediet hediet closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants