-
-
Notifications
You must be signed in to change notification settings - Fork 808
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
Lsp/inlay hints on pipes and functions #3290
base: main
Are you sure you want to change the base?
Conversation
Hi @lpil the PR is almost ready for review. If not, could we consider merging the PR (once it's reviewed) as dead code? (e.g. setting the |
64afe96
to
9f46fff
Compare
How would the programmer turn it on in this case? I think they need to be able to turn it on and add as needed in a straightforward fashion. |
It wouldn't be possible. What I was proposing was either:
Otherwise I can just try to implement the config part in this PR |
697960d
to
2d52e9e
Compare
9ed02ef
to
7894a79
Compare
@lpil I think that should be it 🙂 |
fe20ce7
to
7894a79
Compare
@lpil I've updated the PR with the description of how to turn the feature on. In general, it requires setting to Depending on the editor, there could be ways to turn it on momentarily (e.g. with a keyboard shortcut) if client and client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then
map('<leader>th', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end, '[T]oggle Inlay [H]ints')
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! Thank you very much for waiting too, I've nearly got through all the compiler PRs 😅
} | ||
|
||
#[derive(Debug, Clone, Deserialize)] | ||
#[serde(rename_all = "camelCase")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snake_case please, we never use camelCase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update: I noticed that for a better integration with vscode, it's better to use camelCase instead
you can take a look at how it is rendered in the client side pr: gleam-lang/vscode-gleam#82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to be done.
|
||
fn configuration_update_received(&mut self, result: serde_json::Value) -> Next { | ||
let Some(first_el) = result.as_array().and_then(|a| a.first()) else { | ||
return Next::MorePlease; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be an error?
} | ||
|
||
fn response(&mut self, response: lsp_server::Response) -> Next { | ||
if let Some(handler) = self.response_handlers.remove(&response.id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would it be valid for there to be a response that we don't have a handler for? Or there being a handler but no result in the response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This question hasn't been answered!
I'm also a bit confused as I can't see where this function is used- where can I find that?
Sorry for keeping it open for a long time; I had less time recently but I might able to make it to the finish line in the following days |
e6b80fd
to
9824c74
Compare
Hello! Sorry, just catch up after my holiday. Is this ready for review? |
Hi Louis, sorry about the wait - I have been a little busy too. There are still a couple of things missing but I should be able to take care of them this week |
db11626
to
f14e019
Compare
Hey @lpil everything should be good to go, except for this couple of bits where I am not sure how to handle error within gleam/compiler-core/src/language_server/messages.rs Lines 253 to 257 in 8b63e33
gleam/compiler-core/src/language_server/messages.rs Lines 271 to 280 in 8b63e33
Should I add a new variant to the |
f55844a
to
bb4652d
Compare
@lpil ready for review 👍 |
fix: fix rebase issues
bb4652d
to
b0b7bd5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I've left some notes inline, and the notes from the previous review still need to be addressed
compiler-core/src/ast/typed.rs
Outdated
@@ -180,6 +180,36 @@ pub enum TypedExpr { | |||
} | |||
|
|||
impl TypedExpr { | |||
/// Determines if the expression is a simple literal whose inlayHints must not be showed | |||
/// in a pipeline chain | |||
pub fn is_simple_lit(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a simple lit?
This documentation seems to be for some other part of the codebase rather than being generic to all uses of the types AST. Perhaps it belongs elsewhere, or the documentation needs to be updated.
} | ||
|
||
#[derive(Debug, Clone, Deserialize)] | ||
#[serde(rename_all = "camelCase")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to be done.
pub pipelines: bool, | ||
|
||
/// Whether to show type inlay hints of function parameters | ||
pub parameter_types: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about function_parameter_types
and function_return_types
? As it doesn't apply to all type parameters
use serde::Deserialize; | ||
use std::sync::{Arc, RwLock}; | ||
|
||
pub type SharedConfig = Arc<RwLock<Configuration>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this alias for clarity please 🙏
|
||
impl<'ast> Visit<'ast> for InlayHintsVisitor<'_> { | ||
fn visit_typed_function(&mut self, fun: &'ast crate::ast::TypedFunction) { | ||
// This must be reset on every statement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be inside the loop of statements? Here it's being reset for every module function definition rather than every statement.
}) | ||
} | ||
|
||
pub fn run(&mut self) -> Result<()> { | ||
self.start_watching_gleam_toml(); | ||
let mut buffer = MessageBuffer::new(); | ||
self.start_watching_config(); | ||
let _ = self.request_configuration(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this discarded value?
@@ -168,6 +207,35 @@ where | |||
} | |||
} | |||
|
|||
fn start_watching_config(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we be more specific with the name please 🙏
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)] | ||
#[serde(default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Configuration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is called configuration here but "user config" elsewhere. Is there a canonical name for this sort of configuration in the protocol?
@@ -269,6 +333,53 @@ where | |||
} | |||
} | |||
|
|||
fn inlay_hints_refresh(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn inlay_hints_refresh(&mut self) { | |
fn send_inlay_hints_refresh_request(&mut self) { |
self.connection | ||
.sender | ||
.send(lsp_server::Message::Request(request)) | ||
.unwrap_or_else(|_| panic!("send {method}")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not discard the error please, otherwise it's hard to debug 🙏
edit: in addition to the inlay hints on pipelines, this PR also implements inlay hints for functions' parameter types (via the
gleam.inlayHints.parameterTypes
option) and for functions' return type (via thegleam.inlayHints.returnTypes
option)Implements #3291
This PR shows inlay hints with the type of a pipeline step (only for pipeline expressions that span across multiple lines). Hints won't be shown for literal values (ints, floats, strings, bitstrings
The functionality is toggled via the
gleam.inlayHints.pipelines
client config optionThe PR uses the
type_::printer::Printer
to pretty print the types, thus all the rigid type vars, aliases, etc are already taken care of, and the output should be consistent with the mouse hover outputThe PR is meant to be read as a whole, not commit by commit
Here's the vscode client PR: gleam-lang/vscode-gleam#82
How to activate hints
Vscode
Once the vscode client pr is merged, it will be possible to toggle the option via the vscode settings
Sublime text
The user will need to enable the functionality in the settings of the LSP sublime extension:
Nvim
The user will need to enable the functionality in the
init.lua
file:Future development
my_fn(/*param_name*/0, /* other_param*/ 100)
let x/*: Int*/ = my_fn()
. Same foruse
bindingscase
patternsCredits
The part of the pr about config is partially based upon this previous pr #2393