Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,31 @@
# Change Log

## 0.9.23
- The DLS now supports most type-level semantics and lookups
- - Goto-functionality from, and to, typedefs work
- - You can goto-type-def on `implement` definitions or references to find their interface typedef
- - Lookups to, and from, structure type members types (including interface types) work
- - Lookups through pointers and arrays types work (only on type level)
- - Lookup to type definitions from locals and method argument symbols and references to the same, generally work
- - Some conservative type-checking semantics are implemented, offering a minimum of feedback for assignment and overrides
- - Unknown types are reported, unless they are considered builtin
- - Various smaller semantics/errors are implemented, related to `bitfield` constructs, templates-as-types, and initializers
- Fixed a case where the DLS would repeatedly cancel its own in-flight analysis when no import paths could be resolved
- Fixed a parser crash when using utf-16 wide characters in documentation strings
- Improved server handling of invalid character literals
- Fixed bug in template cycle detection that could cause crashes when an object
instantiated a template involved in a cycle
- Fixed bug in parser that could cause hangs when parsing broken 'layout' types
- Adjusted range for error report related to mismatching `memoized` methods
- The DLS will now report an error when a method override mismatches `startup` or `independent` qualifiers
- Adjusted range for error report related to overriding non-default methods
- The DLS will now report an error if it cannot determine a most-overriding method in an object
- The DLS will now report ambiguous parameter overrides, even if these are hidden below a valid override
- The DLS will now report an error if you declare multiple index variables of the same non-'_' name in a declaration
- The DLS will now report `error` objects using their error message, mimicking DMLC reports more closely
- Fixed the lookup of various symbols in nested scopes, including in method, switch, `#if`, and `after` scopes
- Reserved keywords are now correctly allowed as identifiers for several declarations
- The DLS will no longer report `error` objects in dead code

## 0.9.22
- Fixed an issue in server logging where the large allocations could be made by debug prints even at lower debug levels
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ name = "fuzzing"
path = "tests/fuzzing.rs"
required-features = ["fuzzing"]

[[test]]
name = "parser_recovery_tests"
path = "tests/parser_recovery_tests.rs"
required-features = ["fuzzing"]

[dependencies]
anyhow = "1.0"
clap = { version = "4.2", features = ["cargo", "derive"] }
Expand Down
29 changes: 20 additions & 9 deletions src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use serde::Deserialize;
use serde_json::json;

use std::collections::{HashMap, HashSet};
use std::cmp::Ordering;
use std::path::{Path, PathBuf};
use std::fs;
use std::sync::atomic::AtomicBool;
Expand Down Expand Up @@ -555,11 +554,14 @@ impl <O: Output> InitActionContext<O> {
// when we have done linting but then turned off the setting
lint.clear();
}
let files: HashSet<&PathBuf> =
let mut files: Vec<&PathBuf> =
isolated.keys()
.chain(device.keys())
.chain(lint.keys())
.collect::<HashSet<_>>()
.into_iter()
.collect();
files.sort();
let direct_opens = self.direct_opens.lock().unwrap();
for file in files {
let Some(canon_path) = CanonPath::from_path_buf(file.clone())
Expand All @@ -577,13 +579,22 @@ impl <O: Output> InitActionContext<O> {
.map(|e|e.with_source("dml-lint")))
.collect();
debug!("Reporting errors for {:?}", file);
// Sort by line
sorted_errors.sort_unstable_by(
|e1, e2|if e1.error.span.range > e2.error.span.range {
Ordering::Greater
} else {
Ordering::Less
});
let severity_order = |severity|match severity {
Some(lsp_types::DiagnosticSeverity::ERROR) => 0,
Some(lsp_types::DiagnosticSeverity::WARNING) => 1,
Some(lsp_types::DiagnosticSeverity::INFORMATION) => 2,
Some(lsp_types::DiagnosticSeverity::HINT) => 3,
Some(_) => 4,
None => 5,
};
sorted_errors.sort_unstable_by(|left, right|
left.error.span.range.cmp(&right.error.span.range)
.then_with(||severity_order(left.error.severity)
.cmp(&severity_order(right.error.severity)))
.then_with(||left.error.description
.cmp(&right.error.description))
.then_with(||left.source.cmp(right.source))
.then_with(||left.error.related.cmp(&right.error.related)));
match parse_uri(file.to_str().unwrap()) {
Ok(url) => notifier.notify_publish_diagnostics(
PublishDiagnosticsParams::new(
Expand Down
55 changes: 54 additions & 1 deletion src/actions/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::actions::{AnalysisProgressKind, AnalysisWaitKind,
ContextDefinition, InitActionContext,
rpc_error_code};
use crate::actions::notifications::ContextDefinitionKindParam;
use crate::actions::semantic_lookup::{DLSLimitation, declarations_at_fp, definitions_at_fp, implementations_at_fp, references_at_fp};
use crate::actions::semantic_lookup::{DLSLimitation, declarations_at_fp, definitions_at_fp, implementations_at_fp, references_at_fp, type_definitions_at_fp};
use crate::analysis::{Named, DeclarationSpan, LocationSpan};
use crate::analysis::symbols::SimpleSymbol;
use crate::config::Config;
Expand All @@ -32,6 +32,7 @@ pub use crate::lsp_data::request::{
GotoDeclaration, GotoDeclarationResponse,
GotoDefinition,
GotoImplementation, GotoImplementationResponse,
GotoTypeDefinition, GotoTypeDefinitionResponse,
HoverRequest,
RangeFormatting,
References,
Expand Down Expand Up @@ -157,6 +158,7 @@ fn structure_to_symbolkind(kind: DMLSymbolKind)
DMLSymbolKind::Loggroup
=> SymbolKind::CONSTANT,
DMLSymbolKind::Extern |
DMLSymbolKind::Field |
DMLSymbolKind::Saved |
DMLSymbolKind::Session |
DMLSymbolKind::Local |
Expand Down Expand Up @@ -570,6 +572,57 @@ impl RequestAction for GotoDefinition {
}
}

impl RequestAction for GotoTypeDefinition {
type Response = ResponseWithMessage<Option<GotoTypeDefinitionResponse>>;

fn timeout() -> std::time::Duration {
crate::server::dispatch::DEFAULT_REQUEST_TIMEOUT * 5
}

fn fallback_response() -> Result<Self::Response, ResponseError> {
Ok(None.into())
}

fn get_identifier(params: &Self::Params) -> String {
Self::request_identifier(
&text_document_position_to_ident(
&params.text_document_position_params))
}

fn handle<O: Output>(
ctx: InitActionContext<O>,
params: Self::Params,
) -> Result<Self::Response, ResponseError> {
debug!("Requesting type definitions with params {:?}", params);
let fp = match ctx.text_doc_pos_to_pos(
&params.text_document_position_params,
"goto_type_def") {
Some(fp) => fp,
None => return Self::fallback_response(),
};
let canon_path = make_canon_path!(fp.path())?;
wait_for_device_path!(ctx, canon_path);

let mut limitations = HashSet::new();
match type_definitions_at_fp(&ctx, &fp, &mut limitations) {
Ok(locations) => {
let locations = locations.into_iter()
.map(|location|ls_util::dls_to_location(&location))
.collect();
Ok(response_maybe_with_limitations(
&fp.path(),
Some(GotoTypeDefinitionResponse::Array(locations)),
limitations,
&ctx))
},
Err(error) => {
warn_miss_lookup(error, fp.path().to_str());
Self::fallback_response()
},
}
}
}

impl RequestAction for References {
type Response = ResponseWithMessage<Vec<Location>>;

Expand Down
61 changes: 52 additions & 9 deletions src/actions/semantic_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ use crate::analysis::scope::{ContextedSymbol, ContextKey};
use crate::analysis::structure::objects::MaybeAbstract;
use crate::analysis::structure::expressions::DMLString;
use crate::analysis::symbols::DMLSymbolKind;
use crate::analysis::templating::types::TypeUse;
use crate::analysis::{DeviceAnalysis, IsolatedAnalysis, LocationSpan, SymbolRef, ZeroRange};

use crate::analysis::parsing::tree::{ZeroSpan, ZeroFilePosition};
use crate::analysis::reference::{CodeReference, Reference, ReferenceKind};
use crate::analysis::reference::{CodeReference, Reference};
use crate::file_management::CanonPath;
use crate::server::Output;

Expand All @@ -42,11 +43,20 @@ impl fmt::Display for DLSLimitation {
}
}

pub fn type_semantic_limitation() -> DLSLimitation {
pub fn typeof_type_limitation() -> DLSLimitation {
DLSLimitation {
issue_num: 65,
description: "The DLS does not currently support semantic analysis of \
types, including reference finding".to_string(),
description: "The DLS does not currently resolve 'typeof' types"
.to_string(),
}
}

pub fn untracked_member_limitation() -> DLSLimitation {
DLSLimitation {
issue_num: 65,
description: "The DLS does not currently resolve members accessed \
on expressions other than plain references, such as \
function calls or casts".to_string(),
}
}

Expand Down Expand Up @@ -133,6 +143,10 @@ impl <'t> SemanticLookup<'t> {
Reference::CodeReference(code_ref) => {
stored_symbols = get_symbols_of_ref(&code_ref, &analysis_info, &mut recognized_limitations);
},
Reference::UntrackedMember(_) => {
recognized_limitations.insert(
untracked_member_limitation());
},
Reference::FileReference(file_ref) => {
targeted_files = get_import_target_of(&file_ref, analysis_lock)
.into_iter().cloned().collect();
Expand Down Expand Up @@ -203,11 +217,6 @@ fn get_refs_and_syms_at_fp<'t>(
}
return Ok(SymbolsOrReference::Symbols(syms));
}
if let Some(refr) = ref_at_pos.and_then(|r|r.as_code_ref()) {
if refr.reference_kind() == ReferenceKind::Type {
relevant_limitations.insert(type_semantic_limitation());
}
}
if let Some(refr) = ref_at_pos {
Ok(SymbolsOrReference::Reference(refr.clone()))
} else {
Expand Down Expand Up @@ -459,3 +468,37 @@ pub fn references_at_fp(context: &InitActionContext<impl Output>,
.flat_map(|s|s.lock().unwrap().references.clone())
.collect())
}

pub fn type_definitions_at_fp(
context: &InitActionContext<impl Output>,
fp: &ZeroFilePosition,
relevant_limitations: &mut HashSet<DLSLimitation>)
-> Result<Vec<ZeroSpan>, AnalysisLookupError> {
let analysis_lock = context.analysis.lock().unwrap();
let mut semantic_lookup = SemanticLookup::create_lookup(
fp,
&analysis_lock,
context)?;
mem::swap(relevant_limitations, &mut semantic_lookup.recognized_limitations);

let mut locations = HashSet::new();
for (device, symbols) in &semantic_lookup.stored_symbols {
for symbol in symbols {
let symbol = symbol.lock().unwrap();
locations.extend(symbol.type_definitions.iter().copied());
match symbol.typed {
Some(TypeUse::Declared(type_id)) => if let Some(declaration) =
device.types.declaration(type_id) {
locations.insert(declaration.name.span);
},
Some(TypeUse::Anonymous(span)) => {
locations.insert(span);
},
None => if symbol.typeof_declared {
relevant_limitations.insert(typeof_type_limitation());
},
}
}
}
Ok(locations.into_iter().collect())
}
Loading
Loading