Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

How to scope the editor models / typescriptDefaults #1105

Closed
ulrichb opened this issue Oct 11, 2018 · 8 comments
Closed

How to scope the editor models / typescriptDefaults #1105

ulrichb opened this issue Oct 11, 2018 · 8 comments
Labels
feature-request Request for new features or functionality typescript typescript-multifile
Milestone

Comments

@ulrichb
Copy link
Contributor

ulrichb commented Oct 11, 2018

I've tried it at StackOverflow, but had no luck...

Any chance advise to scope the changes to monaco.languages.typescript or the "editor models".

Background: I want to host multiple Monaco editors with different sets of models (maybe also different typescriptDefaults).

@ulrichb ulrichb changed the title How to scope How to scope the editor models / typescriptDefaults Oct 11, 2018
@alexdima
Copy link
Member

alexdima commented Nov 10, 2018

This is outside the scope of the monaco-typescript project. I recommend that you fork the project and implemented that on your side. Currently, that is built to have a single TypeScript language server host which exposes all the models together to typescript.

One alternative idea to cheat would be to think about user focus... i.e. an user can only work with at most 1 editor at a time. So you can use a different language id, e.g. ts2 for all editors until they gain focus. Once focus is gained, you can change the language to typescript and then the TS compiler will only see that one model. Once the editor is blurred, you can change the language id back to ts2.

Then, you can defined a monarch colorizer for ts2 which would be the same one as for TypeScript.... Diagnostics will be removed, but other than that this could simulate what you desire...

Good luck!

@ulrichb
Copy link
Contributor Author

ulrichb commented Nov 12, 2018

Okay, thanks for the info that this scenario is not supported at the moment.

About the thing with the second language id ("ts2"): Is what you mean with the "ts2" language a "fake" language without semantic model, but just a syntax highlighting enabled editor? => No error squiggles in the (non-focused) "ts2" editors, only in the focused "typescript" editor. And when changing the focus between the editors, I also need to switch the global editor models (dispose all, and create them for the focused editor).

@alexdima
Copy link
Member

Is what you mean with the "ts2" language a "fake" language without semantic model, but just a syntax highlighting enabled editor

Yes

And when changing the focus between the editors, I also need to switch the global editor models (dispose all, and create them for the focused editor).

No, I think you just need to implement the following:

editors.forEach(function(editor) {
	editor.onDidBlurEditorWidget(() => {
        monaco.editor.setModelLanguage(editor.getModel(), 'ts2')
    });
    editor.onDidFocusEditorWidget(() => {
        monaco.editor.setModelLanguage(editor.getModel(), 'typescript')
    });
});

I'm not sure how well it's gonna work, but this is the cheapest I can think of to simulate something similar to what you describe.

@ulrichb
Copy link
Contributor Author

ulrichb commented Nov 13, 2018

@alexandrudima Each of my editors has a different (only partially overlapping) set of editor models (the one it displays and N non-visible/dependency models). This is why I think it's necessary to dispose all current editor models and loading "the current set" when switching focus. => To completely isolate them (avoid conflicts of duplicate type definitions, model URLs, ...).

@alexdima
Copy link
Member

Each of my editors has a different (only partially overlapping) set of editor models (the one it displays and N non-visible/dependency models)

👍 Ok, I didn't know that.

@ulrichb
Copy link
Contributor Author

ulrichb commented Nov 14, 2018

@alexandrudima Again thanks for your support.

@tarb
Copy link

tarb commented Sep 23, 2019

Is what you mean with the "ts2" language a "fake" language without semantic model, but just a syntax highlighting enabled editor

Yes

And when changing the focus between the editors, I also need to switch the global editor models (dispose all, and create them for the focused editor).

No, I think you just need to implement the following:

editors.forEach(function(editor) {
	editor.onDidBlurEditorWidget(() => {
        monaco.editor.setModelLanguage(editor.getModel(), 'ts2')
    });
    editor.onDidFocusEditorWidget(() => {
        monaco.editor.setModelLanguage(editor.getModel(), 'typescript')
    });
});

I'm not sure how well it's gonna work, but this is the cheapest I can think of to simulate something similar to what you describe.

Anybody get this to work? Im putting in a tabbed editor, (where you write seperate non related snippets of ts that control automation tasks) and changing the models language doest seem to remove it from being used by the language server? and I still get "cannot redeclare ... etc". The approach is similar to above, set all models to plaintext on tab change, except the tab your changing too - which you set back to ts. All the relevant events fire and indicate that all models have changed - so I dont think its as much me doing it wrong as it not being supported?

Ive looked at dispose removes the model from use in the language server like I want, and I could use this - but I would like to keep the undo history on tab change, and I cant see a way of doing this when you dispose all models and create the new model for the new tab each time.

Thanks, would love any other ideas for this

@thedanielhanke
Copy link

Any news on this topic?

@microsoft microsoft locked and limited conversation to collaborators Mar 10, 2023
@hediet hediet converted this issue into discussion #3783 Mar 10, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
feature-request Request for new features or functionality typescript typescript-multifile
Projects
None yet
Development

No branches or pull requests

4 participants