Skip to content

Commit

Permalink
Collect module kind span for ParseModule (FuelLabs#4822)
Browse files Browse the repository at this point in the history
## Description
This PR replaces collecting the dummy spans for the module kind token
with the span of the module kind.

These were introduced in FuelLabs#4232. This was causing an issue in the
language server where we were unable to debug parsed tokens as warnings
if the span was all 0's.

closes FuelLabs#4809
  • Loading branch information
JoshuaBatty authored Jul 21, 2023
1 parent 5318edd commit b33b63c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions sway-core/src/language/parsed/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct ParseModule {
/// Submodules introduced within this module using the `dep` syntax in order of declaration.
pub submodules: Vec<(ModName, ParseSubmodule)>,
pub attributes: transform::AttributesMap,
/// The span of the module kind.
pub module_kind_span: Span,
/// an empty span at the beginning of the file containing the module
pub span: Span,
}
Expand Down
4 changes: 4 additions & 0 deletions sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ fn parse_in_memory(
engines,
module.value.clone(),
)?;
let module_kind_span = module.value.kind.span().clone();
let submodules = Default::default();
let attributes = module_attrs_to_map(handler, &module.attribute_list)?;
let root = parsed::ParseModule {
span: span::Span::dummy(),
module_kind_span,
tree,
submodules,
attributes,
Expand Down Expand Up @@ -301,6 +303,7 @@ fn parse_module_tree(
engines,
module.value.clone(),
)?;
let module_kind_span = module.value.kind.span().clone();
let attributes = module_attrs_to_map(handler, &module.attribute_list)?;

let lexed = lexed::LexedModule {
Expand All @@ -310,6 +313,7 @@ fn parse_module_tree(
let source_id = engines.se().get_source_id(&path.clone());
let parsed = parsed::ParseModule {
span: span::Span::new(src, 0, 0, Some(source_id)).unwrap(),
module_kind_span,
tree,
submodules: submodules.parsed,
attributes,
Expand Down
1 change: 1 addition & 0 deletions sway-core/src/semantic_analysis/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl ty::TyModule {
tree,
attributes,
span,
..
} = parsed;

// Type-check submodules first in order of declaration.
Expand Down
24 changes: 13 additions & 11 deletions sway-lsp/src/server_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@ impl ServerState {
// take over the normal error and warning display behavior
// and instead show the either the parsed or typed tokens as warnings.
// This is useful for debugging the lsp parser.
Warnings::Parsed => diagnostics_to_publish
.extend(debug::generate_warnings_for_parsed_tokens(tokens)),
Warnings::Parsed => {
diagnostics_to_publish = debug::generate_warnings_for_parsed_tokens(tokens)
}
Warnings::Typed => {
diagnostics_to_publish.extend(debug::generate_warnings_for_typed_tokens(tokens))
diagnostics_to_publish = debug::generate_warnings_for_typed_tokens(tokens)
}
Warnings::Default => {
let diagnostics = session.wait_for_parsing();
if config.diagnostic.show_warnings {
diagnostics_to_publish.extend(diagnostics.warnings);
}
if config.diagnostic.show_errors {
diagnostics_to_publish.extend(diagnostics.errors);
}
}
Warnings::Default => {}
}
let diagnostics = session.wait_for_parsing();
if config.diagnostic.show_warnings {
diagnostics_to_publish.extend(diagnostics.warnings);
}
if config.diagnostic.show_errors {
diagnostics_to_publish.extend(diagnostics.errors);
}
diagnostics_to_publish
};
Expand Down
6 changes: 3 additions & 3 deletions sway-lsp/src/traverse/parsed_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ impl<'a> ParsedTree<'a> {

fn collect_parse_module(&self, parse_module: &ParseModule) {
self.ctx.tokens.insert(
to_ident_key(&Ident::new(parse_module.span.clone())),
to_ident_key(&Ident::new(parse_module.module_kind_span.clone())),
Token::from_parsed(
AstToken::LibrarySpan(parse_module.span.clone()),
SymbolKind::Module,
AstToken::LibrarySpan(parse_module.module_kind_span.clone()),
SymbolKind::Keyword,
),
);
for (
Expand Down

0 comments on commit b33b63c

Please sign in to comment.