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

Easy workspace-wide Regal toggle #113

Open
johanfylling opened this issue Mar 14, 2024 · 8 comments
Open

Easy workspace-wide Regal toggle #113

johanfylling opened this issue Mar 14, 2024 · 8 comments

Comments

@johanfylling
Copy link
Collaborator

Sometimes, you're working in a workspace where you, for various reasons, don't want to change the source code to comply with Regal, or disable it through inline comments or introducing a regal config file. For these situations, it'd be great to have a boolean extension config param to turn off Regal, which could be applied on the workspace. The workspace's .vscode directory, where the config is stored, is likely to be captured by any existing.gitignore.

@anderseknert
Copy link
Member

Agreed, this would be great when working with code you can't modify and fix.

I would love to have a little Regal viking next to the GitHub co-pilot whateverthatis to bring up a context menu with some options related to Regal 😍 But just being able to set it via the usual context menu is fine, and I guess less intrusive for people not as obsessed by Regal (if such people exist). Disabling Regal for the current workspace would be a good first option to add.

Screenshot 2024-03-14 at 13 40 40

@anderseknert
Copy link
Member

As more features are added to the Regal language server, it's likely just the diagnostics feature (i.e. linting) that one might want to disable. There should be little need to disable something like tooltips for built-in functions even when working with code you can't modify. I know that's what you meant @johanfylling, just noting it down for when we get to this.

@charlieegan3
Copy link
Collaborator

If you generally want a language server (such as regal), but then don't want it in one workspace you can create a file at .vscode/settings.json with the contents:

{
    "opa.languageServers": [],
}
Screen.Recording.2024-04-04.at.10.05.10.mov

Clearly there are more high tech options here too. But this might be good enough for someone searching and finding this issue before we do anything nicer.

@charlieegan3
Copy link
Collaborator

I think the right way to look at this now is, how can I disable Regal's linting for a workspace since it's unlikely that you'd want to disable the other functions of the language server in the same way (i.e. they'd be managed in the client settings rather than Regal).

Anders has suggested a command or similar that splats out a disable regal linting config file like this:

rules:
  default:
    level: ignore

I think this is the right end goal, but I'm not sure how we can offer such a command. One idea is to have a StatusBarItem which allows the user to run some commands.

e.g.

Screen.Recording.2024-04-22.at.18.35.56.mov

@anderseknert
Copy link
Member

Love the status bar! :) Adding a .regal/config.yaml file is the right choice for projects you own, but as @johanfylling pointed out, it'd be good if there was an option to disable linting without touching any files in a project, as it might not be yours to begin with. I haven't looked into how it works, but it seems there are "dynamic registration" properties for most things in the LSP configuration, suggesting that it's possible for the client to register/deregister support for features after initialization. But it could be just me misinterpreting the spec.

@charlieegan3
Copy link
Collaborator

charlieegan3 commented Apr 23, 2024

without touching any files in a project

One issue that I see with this is that I don't think we have a good way to 'save' the setting for the next start up in that workspace.

"dynamic registration"

Yeah, I don't know how to disable diagnostics only. That see to me to be worth looking into. It seems we set this in the Regal client settings:

        diagnosticPullOptions: {
            onChange: true,
            onSave: true
        }

This means that the client will request diagnostics when the file is changed and saved. If we set these to false, then this doesn't happen. However, our server will also send diagnostics when the contents of the file change anyway. I think this is something that we'd need to change in the behaviour of the server to address.

I've not been able to see how diagnosticPullOptions could be set by a user at runtime though, so we might need to expose a setting for that the user can change, and that'd be a settings.json file... 🤷‍♂️

@anderseknert
Copy link
Member

Solid research! Yeah, could be that we'll need to add a button or menu item for that somewhere in the VS Code UI ourselves. But let's start by supporting it properly in Regal.

@charlieegan3
Copy link
Collaborator

Interestingly, it doesn't seem to be possible to stop the client from sending textDocument/diagnostic requests 😞. It sends fewer with the above settings on false, but it still sends them and so the server responds with the results.

It also doesn't seem to be featured in the client initialisation options.

I think the way to do this would be to have a setting, much like this one: https://github.com/bmewburn/vscode-intelephense/blob/master/package.json#L508-L513

and have a client-side middleware to drop diagnostics if the feature was off.

const clientOptions: LanguageClientOptions = {
    ...
    middleware: {
        // Optionally ignore diagnostics messages based on config
        handleDiagnostics: (uri, diagnostics, next) => {
            // next(uri, []); // Send empty diagnostics array to suppress them
        }
    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants