Skip to content

Add an extension setting to control inlay hints #1526

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rbenegal
Copy link
Contributor

Add an extension setting that controls [swift] language inlay hints so that hints can be disabled by default for now. Most other language extensions have inlay hints turned off by default (particularly for inferred variable types), likely because it is tricky to figure out how to turn them off/on otherwise.

Later on, when there is a walkthrough mode, we can provide users with an option to set inlay hints on or off when the extension runs for the first time.

Issue: #1512

Add an extension setting that controls `[swift]` inlay hints so that
hints can be disabled by default for now. Most other language extensions
have inlay hints turned off by default, likely because it is tricky to
figure out how to turn them off/on otherwise.

Later on, when there is a walkthrough mode, we can provide users with
an option to set inlay hints on or off when the extension runs for the
first time.

Issue: swiftlang#1512
}

const config = vscode.workspace.getConfiguration("", { languageId: "swift" });
await config.update(
Copy link
Contributor

@plemarquand plemarquand Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to automatically add a .vscode/settings.json file for every package opened in VS Code and add the following to it:

    "[swift]": {
        "editor.inlayHints.enabled": "off"
    }

When I update .vscode/settings.json to set this value to "on", save, and reload the window it gets re-written to "off".

Automatically resetting the setting aside, I don't think we should be generating a settings.json for the user at all as these are meant to be for the user to control, not an extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, yes agreed that touching settings.json automatically is probably not welcome (although we do touch the settings.json for other things like swift environment variables, for example, but the user would have to set them manually I think). Any other suggestions on how the inlay hints could be disabled by default so that new users who don't know how to turn this setting off are not annoyed?

Could send a setting to sourcekit-lsp separately to turn off inlay hints possibly, and then if the user says:

  "[swift]": {
        "editor.inlayHints.enabled": "on"
    }

or sets swift.inlayHints.enabled to true then it would turn on inlay hints?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do other extensions handle this? Do popular language extensions they swim against the VS Code defaults?

My gut feeling is we should tell sourcekit-lsp to disable them unless there is a setting set explicitly that turns them on, but because the default for editor.inlayHints.enabled is "on" I dont know if we can tell if this is explicitly set by the user or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good ideas thanks, it seems like most do it with passing in flags to lsp (Go does it with gopls and rust with rust-analyser), although it looks like C/C++ use vscode api's to override inlayHint behaviour directly.

You are correct that it's not possible to tell whether editor.inlayHints.enabled is explicitly set to on. So it's looking like I'll just have to add functionality like the sourcekit-lsp.inlayHints.enabled setting had at one point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the inspect() method to find out if the user has explicitly configured a setting. Have a look at https://github.com/swiftlang/vscode-swift/blob/main/src/configuration.ts#L245 for an example in the Swift extension's configuration. It will even tell you if it has been configured for a particular language.

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

Successfully merging this pull request may close these issues.

3 participants