-
Notifications
You must be signed in to change notification settings - Fork 74
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the VS Code Swift open source project | ||
// | ||
// Copyright (c) 2025 the VS Code Swift project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import * as vscode from "vscode"; | ||
import configuration from "../configuration"; | ||
|
||
/** | ||
* Configures editor.inlayHints.enabled settings based on swift.inlayHints.enabled settings | ||
*/ | ||
export async function toggleInlayHints() { | ||
let settingValue = undefined; | ||
|
||
if (!configuration.inlayHintsEnabled) { | ||
settingValue = "off"; | ||
} | ||
|
||
const config = vscode.workspace.getConfiguration("", { languageId: "swift" }); | ||
await config.update( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
or sets There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just saw this PR (swiftlang/sourcekit-lsp#2156), and i tracked back the discussion to here.
rust-analyzer (which is basically our sourcekit-lsp) has a bunch of settings for different kinds of inlay hints which are exposed through the VSCode extension as well. There are a lot of settings so I could have missed something but there doesn't appear to be a rust-specific settings to completely turn off inlay hints. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this @MahdiBM. I think most other LSPs have several options for inlay hints, but as far as I understand sourcekit-lsp only provides them for inferred variable type names. So, I think for now it'll just be one inlay hint setting that will control this. For sure more options can be added once sourcekit-lsp provides inlay hints with the same level of granularity as other LSPs. Also, I'm trying out some options on the LSP side to control this here - currently just the flag at startup, but need to look into using capabilities directly so the server doesn't need to be restarted every time (thanks to Mahdi linking this as well): swiftlang/sourcekit-lsp#2156 |
||
"editor.inlayHints.enabled", | ||
settingValue, | ||
vscode.ConfigurationTarget.Workspace, | ||
true | ||
); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.