Skip to content

Commit

Permalink
feat: LSP document symbol (#5532)
Browse files Browse the repository at this point in the history
# Description

## Problem

Resolves #5533

## Summary

With this you can see where you are at any time, and jump to any symbol
in the document.



https://github.com/user-attachments/assets/74ebdb36-cd51-4afc-a33e-775156c1317b




## Additional Context

None

## Documentation

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist

- [x] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
asterite authored Jul 17, 2024
1 parent 5bbce79 commit 1fabcde
Show file tree
Hide file tree
Showing 7 changed files with 817 additions and 26 deletions.
23 changes: 9 additions & 14 deletions compiler/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,8 @@ impl FunctionDefinition {
return_visibility: Visibility::Private,
}
}
}

impl Display for FunctionDefinition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{:?}", self.attributes)?;

pub fn signature(&self) -> String {
let parameters = vecmap(&self.parameters, |Param { visibility, pattern, typ, span: _ }| {
if *visibility == Visibility::Public {
format!("{pattern}: {visibility} {typ}")
Expand All @@ -827,15 +823,14 @@ impl Display for FunctionDefinition {
format!(" -> {}", self.return_type)
};

write!(
f,
"fn {}({}){}{} {}",
self.name,
parameters.join(", "),
return_type,
where_clause_str,
self.body
)
format!("fn {}({}){}{}", self.name, parameters.join(", "), return_type, where_clause_str)
}
}

impl Display for FunctionDefinition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{:?}", self.attributes)?;
write!(f, "fn {} {}", self.signature(), self.body)
}
}

Expand Down
14 changes: 9 additions & 5 deletions tooling/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use async_lsp::{
use fm::{codespan_files as files, FileManager};
use fxhash::FxHashSet;
use lsp_types::{
request::{HoverRequest, InlayHintRequest, PrepareRenameRequest, References, Rename},
request::{
DocumentSymbolRequest, HoverRequest, InlayHintRequest, PrepareRenameRequest, References,
Rename,
},
CodeLens,
};
use nargo::{
Expand All @@ -45,10 +48,10 @@ use notifications::{
on_did_open_text_document, on_did_save_text_document, on_exit, on_initialized,
};
use requests::{
on_code_lens_request, on_formatting, on_goto_declaration_request, on_goto_definition_request,
on_goto_type_definition_request, on_hover_request, on_initialize, on_inlay_hint_request,
on_prepare_rename_request, on_profile_run_request, on_references_request, on_rename_request,
on_shutdown, on_test_run_request, on_tests_request,
on_code_lens_request, on_document_symbol_request, on_formatting, on_goto_declaration_request,
on_goto_definition_request, on_goto_type_definition_request, on_hover_request, on_initialize,
on_inlay_hint_request, on_prepare_rename_request, on_profile_run_request,
on_references_request, on_rename_request, on_shutdown, on_test_run_request, on_tests_request,
};
use serde_json::Value as JsonValue;
use thiserror::Error;
Expand Down Expand Up @@ -126,6 +129,7 @@ impl NargoLspService {
.request::<request::GotoDefinition, _>(on_goto_definition_request)
.request::<request::GotoDeclaration, _>(on_goto_declaration_request)
.request::<request::GotoTypeDefinition, _>(on_goto_type_definition_request)
.request::<DocumentSymbolRequest, _>(on_document_symbol_request)
.request::<References, _>(on_references_request)
.request::<PrepareRenameRequest, _>(on_prepare_rename_request)
.request::<Rename, _>(on_rename_request)
Expand Down
Loading

0 comments on commit 1fabcde

Please sign in to comment.