Skip to content
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
wants to merge 14 commits into from
2 changes: 2 additions & 0 deletions vhdl_lang/src/analysis/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ impl<'a> AnalyzeContext<'a> {
sensitivity_list,
decl,
statements,
start_token: _,
semi_token: _,
} = process;
if let Some(sensitivity_list) = sensitivity_list {
match sensitivity_list {
Expand Down
6 changes: 3 additions & 3 deletions vhdl_lang/src/analysis/design_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ impl<'a> AnalyzeContext<'a> {
);

if let Some(ref mut list) = unit.generic_clause {
self.analyze_interface_list(&mut primary_region, list, diagnostics)?;
self.analyze_interface_list(&mut primary_region, &mut list.items, diagnostics)?;
}
if let Some(ref mut list) = unit.port_clause {
self.analyze_interface_list(&mut primary_region, list, diagnostics)?;
self.analyze_interface_list(&mut primary_region, &mut list.items, diagnostics)?;
}
self.analyze_declarative_part(&mut primary_region, &mut unit.decl, diagnostics)?;
self.analyze_concurrent_part(&mut primary_region, &mut unit.statements, diagnostics)?;
Expand Down Expand Up @@ -148,7 +148,7 @@ impl<'a> AnalyzeContext<'a> {
);

if let Some(ref mut list) = unit.generic_clause {
self.analyze_interface_list(&mut primary_region, list, diagnostics)?;
self.analyze_interface_list(&mut primary_region, &mut list.items, diagnostics)?;
}
self.analyze_declarative_part(&mut primary_region, &mut unit.decl, diagnostics)?;

Expand Down
74 changes: 65 additions & 9 deletions vhdl_lang/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +24,8 @@ pub use any_design_unit::*;

use crate::data::*;

pub use crate::data::KeyWordToken;

/// LRM 15.8 Bit string literals
#[derive(PartialEq, Copy, Clone, Debug)]
pub enum BaseSpecifier {
Expand Down Expand Up @@ -622,6 +624,15 @@ pub enum InterfaceDeclaration {
Package(InterfacePackageDeclaration),
}

#[derive(PartialEq, Debug, Clone)]
pub struct InterfaceList {
pub items: Vec<InterfaceDeclaration>,

// Tokens
pub start_token: KeyWordToken, // port/generiv/parameter
pub semi_token: KeyWordToken,
}

#[derive(PartialEq, Debug, Clone, Copy)]
pub enum Mode {
In,
Expand All @@ -631,11 +642,6 @@ pub enum Mode {
Linkage,
}

#[derive(PartialEq, Debug, Clone)]
pub struct PortClause {
pub port_list: Vec<InterfaceDeclaration>,
}

/// LRM 6.8 Component declarations
#[derive(PartialEq, Debug, Clone)]
pub struct ComponentDeclaration {
Expand Down Expand Up @@ -859,6 +865,10 @@ pub struct BlockStatement {
pub header: BlockHeader,
pub decl: Vec<Declaration>,
pub statements: Vec<LabeledConcurrentStatement>,

// Tokens
pub block_token: KeyWordToken,
pub semi_token: KeyWordToken,
}

/// LRM 11.2 Block statement
Expand All @@ -883,6 +893,10 @@ pub struct ProcessStatement {
pub sensitivity_list: Option<SensitivityList>,
pub decl: Vec<Declaration>,
pub statements: Vec<LabeledSequentialStatement>,

// Tokens
pub start_token: KeyWordToken, // postponed/process
pub semi_token: KeyWordToken,
}

/// LRM 11.4 Concurrent procedure call statements
Expand Down Expand Up @@ -997,6 +1011,12 @@ pub enum ContextItem {
pub struct ContextDeclaration {
pub ident: Ident,
pub items: ContextClause,

// Tokens
pub context_token: KeyWordToken,
pub is_token: KeyWordToken,
pub end_token: KeyWordToken,
pub semi_token: KeyWordToken,
}

/// LRM 4.9 Package instatiation declaration
Expand All @@ -1006,6 +1026,10 @@ pub struct PackageInstantiation {
pub ident: Ident,
pub package_name: WithPos<SelectedName>,
pub generic_map: Option<Vec<AssociationElement>>,

// Tokens
pub package_token: KeyWordToken,
pub semi_token: KeyWordToken,
}

/// LRM 7.3 Configuration specification
Expand Down Expand Up @@ -1093,17 +1117,30 @@ pub struct ConfigurationDeclaration {
pub decl: Vec<ConfigurationDeclarativeItem>,
pub vunit_bind_inds: Vec<VUnitBindingIndication>,
pub block_config: BlockConfiguration,

// Tokens
pub configuration_token: KeyWordToken,
pub is_token: KeyWordToken,
pub end_token: KeyWordToken,
pub semi_token: KeyWordToken,
}

/// LRM 3.2 Entity declarations
#[derive(PartialEq, Debug, Clone)]
pub struct EntityDeclaration {
pub context_clause: ContextClause,
pub ident: Ident,
pub generic_clause: Option<Vec<InterfaceDeclaration>>,
pub port_clause: Option<Vec<InterfaceDeclaration>>,
pub generic_clause: Option<InterfaceList>,
pub port_clause: Option<InterfaceList>,
pub decl: Vec<Declaration>,
pub statements: Vec<LabeledConcurrentStatement>,

// Tokens
pub entity_token: KeyWordToken,
pub is_token: KeyWordToken,
pub begin_token: Option<KeyWordToken>,
pub end_token: KeyWordToken,
pub semi_token: KeyWordToken,
}
/// LRM 3.3 Architecture bodies
#[derive(PartialEq, Debug, Clone)]
Expand All @@ -1113,15 +1150,28 @@ pub struct ArchitectureBody {
pub entity_name: WithRef<Ident>,
pub decl: Vec<Declaration>,
pub statements: Vec<LabeledConcurrentStatement>,

// Tokens
pub architecture_token: KeyWordToken,
pub is_token: KeyWordToken,
pub begin_token: KeyWordToken,
pub end_token: KeyWordToken,
pub semi_token: KeyWordToken,
}

/// LRM 4.7 Package declarations
#[derive(PartialEq, Debug, Clone)]
pub struct PackageDeclaration {
pub context_clause: ContextClause,
pub ident: Ident,
pub generic_clause: Option<Vec<InterfaceDeclaration>>,
pub generic_clause: Option<InterfaceList>,
pub decl: Vec<Declaration>,

// Tokens
pub package_token: KeyWordToken,
pub is_token: KeyWordToken,
pub end_token: KeyWordToken,
pub semi_token: KeyWordToken,
}

/// LRM 4.8 Package bodies
Expand All @@ -1130,6 +1180,12 @@ pub struct PackageBody {
pub context_clause: ContextClause,
pub ident: WithRef<Ident>,
pub decl: Vec<Declaration>,

// Tokens
pub package_token: KeyWordToken,
pub is_token: KeyWordToken,
pub end_token: KeyWordToken,
pub semi_token: KeyWordToken,
}

/// LRM 13.1 Design units
Expand Down
9 changes: 9 additions & 0 deletions vhdl_lang/src/ast/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ impl Search for LabeledConcurrentStatement {
sensitivity_list,
decl,
statements,
start_token: _,
semi_token: _,
} = process;
return_if_found!(sensitivity_list.search(searcher));
return_if_found!(decl.search(searcher));
Expand Down Expand Up @@ -883,6 +885,13 @@ impl Search for InterfaceDeclaration {
}
}

impl Search for InterfaceList {
fn search(&self, searcher: &mut impl Searcher) -> SearchResult {
return_if_found!(self.items.search(searcher));
NotFound
}
}

impl Search for SubprogramDeclaration {
fn search(&self, searcher: &mut impl Searcher) -> SearchResult {
match self {
Expand Down
9 changes: 3 additions & 6 deletions vhdl_lang/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions vhdl_lang/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod message;
mod source;
mod symbol_table;

pub use crate::syntax::KeyWordToken;
pub use contents::*;
pub use diagnostic::*;
pub use latin_1::*;
Expand Down
5 changes: 2 additions & 3 deletions vhdl_lang/src/data/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions vhdl_lang/src/data/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion vhdl_lang/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ mod waveform;
pub mod test;

pub use parser::{ParserResult, VHDLParser};
pub use tokens::Symbols;
pub use tokens::{KeyWordToken, Symbols};
Loading