-
Notifications
You must be signed in to change notification settings - Fork 64
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
WIP: textDocument/documentSymbol (Outline) #75
Closed
Closed
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a99a0b3
Add source range to design units
Bochlin c4ca333
Add source range to context declaration
Bochlin bbb8d96
Add source range to ContextDeclaration
Bochlin 0269d3a
Add document_symbol
Bochlin 2e9bfab
clippy
Bochlin 2a6f388
cargo fmt
Bochlin 0f1f513
Add HasSymbolKind trait
Bochlin 404f841
Add textDocument/documentSymbol for design units
Bochlin c40ec06
Copyright year
Bochlin 5fbccda
Fix clippy 1.43
Bochlin 4656ac2
Remove redundant match from document symbol tests
Bochlin 2ad24cd
Remove hard coded ranges from tests
Bochlin 718545d
cargo fmt
Bochlin 42bb506
Add token fields to AST and add document symbols
Bochlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2018, Olof Kraigher [email protected] | ||
// Copyright (c) 2020, Olof Kraigher [email protected] | ||
|
||
// Allowing this, since box_patterns are feature gated: https://github.com/rust-lang/rfcs/pull/469 | ||
// Track here: https://github.com/rust-lang/rust/issues/29641 | ||
|
@@ -997,6 +997,9 @@ pub enum ContextItem { | |
pub struct ContextDeclaration { | ||
pub ident: Ident, | ||
pub items: ContextClause, | ||
|
||
// Non-LRM fields | ||
pub source_range: SrcPos, | ||
} | ||
|
||
/// LRM 4.9 Package instatiation declaration | ||
|
@@ -1006,6 +1009,9 @@ pub struct PackageInstantiation { | |
pub ident: Ident, | ||
pub package_name: WithPos<SelectedName>, | ||
pub generic_map: Option<Vec<AssociationElement>>, | ||
|
||
// Non-LRM fields | ||
pub source_range: SrcPos, | ||
} | ||
|
||
/// LRM 7.3 Configuration specification | ||
|
@@ -1093,6 +1099,9 @@ pub struct ConfigurationDeclaration { | |
pub decl: Vec<ConfigurationDeclarativeItem>, | ||
pub vunit_bind_inds: Vec<VUnitBindingIndication>, | ||
pub block_config: BlockConfiguration, | ||
|
||
// Non-LRM fields | ||
pub source_range: SrcPos, | ||
} | ||
|
||
/// LRM 3.2 Entity declarations | ||
|
@@ -1104,6 +1113,9 @@ pub struct EntityDeclaration { | |
pub port_clause: Option<Vec<InterfaceDeclaration>>, | ||
pub decl: Vec<Declaration>, | ||
pub statements: Vec<LabeledConcurrentStatement>, | ||
|
||
// Non-LRM fields | ||
pub source_range: SrcPos, | ||
} | ||
/// LRM 3.3 Architecture bodies | ||
#[derive(PartialEq, Debug, Clone)] | ||
|
@@ -1113,6 +1125,9 @@ pub struct ArchitectureBody { | |
pub entity_name: WithRef<Ident>, | ||
pub decl: Vec<Declaration>, | ||
pub statements: Vec<LabeledConcurrentStatement>, | ||
|
||
// Non-LRM fields | ||
pub source_range: SrcPos, | ||
} | ||
|
||
/// LRM 4.7 Package declarations | ||
|
@@ -1122,6 +1137,9 @@ pub struct PackageDeclaration { | |
pub ident: Ident, | ||
pub generic_clause: Option<Vec<InterfaceDeclaration>>, | ||
pub decl: Vec<Declaration>, | ||
|
||
// Non-LRM fields | ||
pub source_range: SrcPos, | ||
} | ||
|
||
/// LRM 4.8 Package bodies | ||
|
@@ -1130,6 +1148,9 @@ pub struct PackageBody { | |
pub context_clause: ContextClause, | ||
pub ident: WithRef<Ident>, | ||
pub decl: Vec<Declaration>, | ||
|
||
// Non-LRM fields | ||
pub source_range: SrcPos, | ||
} | ||
|
||
/// LRM 13.1 Design units | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,18 @@ | |
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2018, Olof Kraigher [email protected] | ||
// Copyright (c) 2020, Olof Kraigher [email protected] | ||
|
||
//! Configuration of the design hierarchy and other settings | ||
|
||
use toml; | ||
|
||
use self::fnv::FnvHashMap; | ||
use self::toml::Value; | ||
use crate::data::*; | ||
use fnv; | ||
use fnv::FnvHashMap; | ||
use std::env; | ||
use std::fs::File; | ||
use std::io; | ||
use std::io::prelude::*; | ||
use std::path::Path; | ||
use toml::Value; | ||
|
||
#[derive(Clone, PartialEq, Default, Debug)] | ||
pub struct Config { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,10 @@ | |
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2018, Olof Kraigher [email protected] | ||
// Copyright (c) 2020, Olof Kraigher [email protected] | ||
|
||
use super::contents::Contents; | ||
use super::diagnostic::{Diagnostic, DiagnosticResult}; | ||
use pad; | ||
use parking_lot::{RwLock, RwLockReadGuard}; | ||
use std::cmp::{max, min}; | ||
use std::collections::hash_map::DefaultHasher; | ||
|
@@ -399,7 +398,7 @@ impl SrcPos { | |
context_lines: u32, | ||
) -> (usize, String) { | ||
let lines = self.get_line_context(context_lines, contents); | ||
use self::pad::{Alignment, PadStr}; | ||
use pad::{Alignment, PadStr}; | ||
// +1 since lines are shown with 1-index | ||
let lineno_len = (self.range.start.line + context_lines + 1) | ||
.to_string() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,13 @@ | |
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2018, Olof Kraigher [email protected] | ||
// Copyright (c) 2020, Olof Kraigher [email protected] | ||
|
||
use super::latin_1::Latin1String; | ||
use parking_lot::RwLock; | ||
use std::sync::Arc; | ||
|
||
use self::fnv::FnvHashMap; | ||
use fnv; | ||
use fnv::FnvHashMap; | ||
|
||
/// Represents a unique string symbol. | ||
/// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2018, Olof Kraigher [email protected] | ||
// Copyright (c) 2020, Olof Kraigher [email protected] | ||
|
||
use super::common::error_on_end_identifier_mismatch; | ||
use super::common::ParseResult; | ||
|
@@ -268,7 +268,7 @@ pub fn parse_configuration_declaration( | |
stream: &mut TokenStream, | ||
diagnostics: &mut dyn DiagnosticHandler, | ||
) -> ParseResult<ConfigurationDeclaration> { | ||
stream.expect_kind(Configuration)?; | ||
let configuration_token = stream.expect_kind(Configuration)?; | ||
let ident = stream.expect_ident()?; | ||
stream.expect_kind(Of)?; | ||
let entity_name = parse_selected_name(stream)?; | ||
|
@@ -301,14 +301,15 @@ pub fn parse_configuration_declaration( | |
if let Some(diagnostic) = error_on_end_identifier_mismatch(&ident, &end_ident) { | ||
diagnostics.push(diagnostic) | ||
} | ||
stream.expect_kind(SemiColon)?; | ||
let semi_token = stream.expect_kind(SemiColon)?; | ||
Ok(ConfigurationDeclaration { | ||
context_clause: ContextClause::default(), | ||
ident, | ||
entity_name, | ||
decl, | ||
vunit_bind_inds, | ||
block_config, | ||
source_range: configuration_token.pos.combine_into(&semi_token), | ||
}) | ||
} | ||
|
||
|
@@ -351,7 +352,8 @@ pub fn parse_configuration_specification( | |
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::syntax::test::Code; | ||
use crate::syntax::test::{source_range, Code}; | ||
use pretty_assertions::assert_eq; | ||
|
||
#[test] | ||
fn empty_configuration() { | ||
|
@@ -375,7 +377,8 @@ end; | |
block_spec: code.s1("rtl(0)").name(), | ||
use_clauses: vec![], | ||
items: vec![], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (3, 4)) | ||
} | ||
); | ||
} | ||
|
@@ -402,7 +405,8 @@ end configuration cfg; | |
block_spec: code.s1("rtl(0)").name(), | ||
use_clauses: vec![], | ||
items: vec![], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (3, 22)), | ||
} | ||
); | ||
} | ||
|
@@ -433,7 +437,8 @@ end configuration cfg; | |
block_spec: code.s1("rtl(0)").name(), | ||
use_clauses: vec![], | ||
items: vec![], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (5, 22)), | ||
} | ||
); | ||
} | ||
|
@@ -466,7 +471,8 @@ end configuration cfg; | |
block_spec: code.s1("rtl(0)").name(), | ||
use_clauses: vec![], | ||
items: vec![], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (5, 22)), | ||
} | ||
); | ||
} | ||
|
@@ -493,7 +499,8 @@ end configuration cfg; | |
block_spec: code.s1("rtl(0)").name(), | ||
use_clauses: vec![], | ||
items: vec![], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (3, 22)), | ||
} | ||
); | ||
} | ||
|
@@ -535,7 +542,8 @@ end configuration cfg; | |
items: vec![], | ||
}) | ||
], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (7, 22)), | ||
} | ||
); | ||
} | ||
|
@@ -580,7 +588,8 @@ end configuration cfg; | |
items: vec![], | ||
}), | ||
}),], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (7, 22)), | ||
} | ||
); | ||
} | ||
|
@@ -636,7 +645,8 @@ end configuration cfg; | |
items: vec![], | ||
}), | ||
}),], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (9, 22)), | ||
} | ||
); | ||
} | ||
|
@@ -683,7 +693,8 @@ end configuration cfg; | |
vunit_bind_inds: Vec::new(), | ||
block_config: None, | ||
}),], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (6, 22)), | ||
} | ||
); | ||
} | ||
|
@@ -761,7 +772,8 @@ end configuration cfg; | |
block_config: None, | ||
}) | ||
], | ||
} | ||
}, | ||
source_range: source_range(&code, (0, 0), (11, 22)), | ||
} | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2018, Olof Kraigher [email protected] | ||
// Copyright (c) 2020, Olof Kraigher [email protected] | ||
|
||
use super::common::error_on_end_identifier_mismatch; | ||
use super::common::ParseResult; | ||
|
@@ -104,19 +104,19 @@ pub fn parse_context( | |
End => { | ||
stream.pop_if_kind(Context)?; | ||
end_ident = stream.pop_optional_ident()?; | ||
stream.expect_kind(SemiColon)?; | ||
break; | ||
} | ||
) | ||
} | ||
|
||
let semi_token = stream.expect_kind(SemiColon)?; | ||
let ident = to_simple_name(name)?; | ||
|
||
diagnostics.push_some(error_on_end_identifier_mismatch(&ident, &end_ident)); | ||
|
||
Ok(DeclarationOrReference::Declaration(ContextDeclaration { | ||
ident, | ||
items, | ||
source_range: context_token.pos.combine_into(&semi_token), | ||
})) | ||
} else { | ||
// Context reference | ||
|
@@ -140,7 +140,8 @@ mod tests { | |
use super::*; | ||
|
||
use crate::data::Diagnostic; | ||
use crate::syntax::test::Code; | ||
use crate::syntax::test::{source_range, Code}; | ||
use pretty_assertions::assert_eq; | ||
|
||
#[test] | ||
fn test_library_clause_single_name() { | ||
|
@@ -246,13 +247,21 @@ context ident is | |
end context ident; | ||
", | ||
]; | ||
for variant in variants { | ||
let source_ranges = vec![ | ||
((0, 0), (1, 4)), | ||
((0, 0), (1, 12)), | ||
((0, 0), (1, 10)), | ||
((0, 0), (1, 18)), | ||
]; | ||
for variant in variants.iter().zip(source_ranges.iter()) { | ||
let (variant, (start, end)) = variant; | ||
let code = Code::new(variant); | ||
assert_eq!( | ||
code.with_stream_no_diagnostics(parse_context), | ||
DeclarationOrReference::Declaration(ContextDeclaration { | ||
ident: code.s1("ident").ident(), | ||
items: vec![] | ||
items: vec![], | ||
source_range: source_range(&code, *start, *end), | ||
}) | ||
); | ||
} | ||
|
@@ -278,7 +287,8 @@ end context ident2; | |
context, | ||
DeclarationOrReference::Declaration(ContextDeclaration { | ||
ident: code.s1("ident").ident(), | ||
items: vec![] | ||
items: vec![], | ||
source_range: source_range(&code, (0, 0), (1, 19)), | ||
}) | ||
); | ||
} | ||
|
@@ -317,7 +327,8 @@ end context; | |
}), | ||
code.s1("context foo.ctx;") | ||
), | ||
] | ||
], | ||
source_range: source_range(&code, (0, 0), (4, 12)), | ||
}) | ||
) | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using hard coded line numbers and colums makes the tests fragile and harder to maintain. I have avoided it so far by using test helper to compute source ranges from textual searches such as finding the nth substring. In this case it would be nice to create a test helper that finds a source range between two substrings instead of hardcoding it.
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.
Makes sense.