mirror of
https://github.com/google/gn-language-server.git
synced 2025-12-23 12:26:43 +00:00
Consider undefined variables within defined()
This commit is contained in:
parent
f1aab25469
commit
21874836d0
4 changed files with 18 additions and 13 deletions
|
|
@ -18,6 +18,7 @@ pub const DECLARE_ARGS: &str = "declare_args";
|
|||
pub const FOREACH: &str = "foreach";
|
||||
pub const SET_DEFAULTS: &str = "set_defaults";
|
||||
pub const FORWARD_VARIABLES_FROM: &str = "forward_variables_from";
|
||||
pub const DEFINED: &str = "defined";
|
||||
|
||||
pub struct BuiltinSymbol {
|
||||
pub name: &'static str,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use tower_lsp::lsp_types::Diagnostic;
|
|||
|
||||
use crate::{
|
||||
analyzer::{AnalyzedFile, Analyzer},
|
||||
common::config::Configurations,
|
||||
diagnostics::{syntax::collect_syntax_errors, undefined::collect_undefined_identifiers},
|
||||
};
|
||||
|
||||
|
|
@ -27,13 +26,13 @@ mod undefined;
|
|||
|
||||
pub fn compute_diagnostics(
|
||||
file: &AnalyzedFile,
|
||||
config: &Configurations,
|
||||
analyzer: &Analyzer,
|
||||
undefined_variable_analysis: bool,
|
||||
request_time: Instant,
|
||||
) -> Vec<Diagnostic> {
|
||||
let mut diagnostics =
|
||||
collect_syntax_errors(file.analyzed_root.block, file.analyzed_root.document);
|
||||
if config.experimental.undefined_variable_analysis {
|
||||
if undefined_variable_analysis {
|
||||
diagnostics.extend(collect_undefined_identifiers(file, analyzer, request_time));
|
||||
}
|
||||
diagnostics
|
||||
|
|
|
|||
|
|
@ -25,7 +25,10 @@ use crate::{
|
|||
AnalyzedBlock, AnalyzedFile, AnalyzedStatement, Analyzer, TopLevelStatementsExt, Variable,
|
||||
VariableMap, WorkspaceAnalyzer,
|
||||
},
|
||||
common::{builtins::BUILTINS, utils::is_exported},
|
||||
common::{
|
||||
builtins::{BUILTINS, DEFINED},
|
||||
utils::is_exported,
|
||||
},
|
||||
parser::{Expr, Identifier, LValue, PrimaryExpr},
|
||||
};
|
||||
|
||||
|
|
@ -118,14 +121,16 @@ impl<'i> PrimaryExpr<'i> {
|
|||
PrimaryExpr::Call(call) => {
|
||||
call.function
|
||||
.collect_undefined_identifiers(file, tracker, diagnostics);
|
||||
for expr in &call.args {
|
||||
expr.collect_undefined_identifiers(
|
||||
file,
|
||||
analyzer,
|
||||
request_time,
|
||||
tracker,
|
||||
diagnostics,
|
||||
);
|
||||
if call.function.name != DEFINED {
|
||||
for expr in &call.args {
|
||||
expr.collect_undefined_identifiers(
|
||||
file,
|
||||
analyzer,
|
||||
request_time,
|
||||
tracker,
|
||||
diagnostics,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
PrimaryExpr::ArrayAccess(array_access) => {
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ pub async fn publish_diagnostics(context: &RequestContext, uri: &Url) {
|
|||
|
||||
let diagnostics = compute_diagnostics(
|
||||
¤t_file,
|
||||
&config,
|
||||
&context.analyzer,
|
||||
config.experimental.undefined_variable_analysis,
|
||||
context.request_time,
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue