Skip to content

Provide context variable for resource to be opened in contentTypeMapping -> enabledWhen - > with statement #393

@ghentschke

Description

@ghentschke

Hi All,
we are developing an LSP based C/C++ editor using the generic text editor and LSP4E. Now I run into the problem that there are several editors for a C/C++ content-type (e.g. org.eclipse.cdt.core.cSource) in Eclipse and LSP4E uses the content-type to run a certain language server.
In our case, the clangd language server shall be used only for new C/C++ Projects which are associated with the new LSP C/C++ editor. Files in old projects shall be opened by the CDT C-Editor without starting a language server when a C-file is opened.
Therefore I'am providing a PropertyTester which checks the file to be opened. This test is used in the enabledWhen statement for the contentTypeMapping in the org.eclipse.lsp4e.languageServer extension point. This ensures that the language server is only enabled, when a certain project nature has been set:

image
with new openResource variable:
image

LSP4E has the information which resource shall be opened. It would be fantastic if this object is forwarded to the context in the org.eclipse.lsp4e.enablement.EnablementTester as a variable to be used in a PropertyTester class. I added a variable named openResource to the evaluate method in the EnablementTester to test my approach:
image

The openResource object can be a IFile, IEditorInput or IDocument which can be checked in the enabledWhen test.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions