Skip to content

Commit 14f1b36

Browse files
committed
feat: add eager flag and workspace symbols feature
Allow passing in an `--eager` flag to the LSP to make it eagerly load all relevant files in the workspace. When this flag is provided, files are not removed from the `last_valid_parse` cache when they are closed. In addition, this flag enables the LSP to provide workspace symbol information.
1 parent 0978484 commit 14f1b36

File tree

6 files changed

+550
-44
lines changed

6 files changed

+550
-44
lines changed

starlark_bin/bin/bazel.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pub(crate) fn main(
141141
prelude: &[PathBuf],
142142
dialect: Dialect,
143143
globals: Globals,
144+
eager: bool,
144145
) -> anyhow::Result<()> {
145146
if !lsp {
146147
return Err(anyhow::anyhow!("Bazel mode only supports `--lsp`"));
@@ -154,6 +155,7 @@ pub(crate) fn main(
154155
is_interactive,
155156
dialect,
156157
globals,
158+
eager,
157159
)?;
158160

159161
ctx.mode = ContextMode::Check;
@@ -173,6 +175,7 @@ pub(crate) struct BazelContext {
173175
pub(crate) globals: Globals,
174176
pub(crate) builtin_docs: HashMap<LspUrl, String>,
175177
pub(crate) builtin_symbols: HashMap<String, LspUrl>,
178+
pub(crate) eager: bool,
176179
}
177180

178181
impl BazelContext {
@@ -187,6 +190,7 @@ impl BazelContext {
187190
module: bool,
188191
dialect: Dialect,
189192
globals: Globals,
193+
eager: bool,
190194
) -> anyhow::Result<Self> {
191195
let prelude: Vec<_> = prelude
192196
.iter()
@@ -263,6 +267,7 @@ impl BazelContext {
263267
}),
264268
external_output_base: output_base
265269
.map(|output_base| PathBuf::from(output_base).join("external")),
270+
eager,
266271
})
267272
}
268273

@@ -886,4 +891,8 @@ impl LspContext for BazelContext {
886891

887892
Ok(names)
888893
}
894+
895+
fn is_eager(&self) -> bool {
896+
self.eager
897+
}
889898
}

starlark_bin/bin/eval.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub(crate) struct Context {
7070
pub(crate) globals: Globals,
7171
pub(crate) builtin_docs: HashMap<LspUrl, String>,
7272
pub(crate) builtin_symbols: HashMap<String, LspUrl>,
73+
pub(crate) eager: bool,
7374
}
7475

7576
/// The outcome of evaluating (checking, parsing or running) given starlark code.
@@ -101,6 +102,7 @@ impl Context {
101102
module: bool,
102103
dialect: Dialect,
103104
globals: Globals,
105+
eager: bool,
104106
) -> anyhow::Result<Self> {
105107
let prelude: Vec<_> = prelude
106108
.iter()
@@ -143,6 +145,7 @@ impl Context {
143145
globals,
144146
builtin_docs,
145147
builtin_symbols,
148+
eager,
146149
})
147150
}
148151

@@ -379,4 +382,8 @@ impl LspContext for Context {
379382
fn get_environment(&self, _uri: &LspUrl) -> DocModule {
380383
DocModule::default()
381384
}
385+
386+
fn is_eager(&self) -> bool {
387+
self.eager
388+
}
382389
}

starlark_bin/bin/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ struct Args {
142142
)]
143143
files: Vec<PathBuf>,
144144

145+
#[arg(long = "eager", help = "In LSP mode, eagerly load all files.")]
146+
eager: bool,
147+
145148
#[arg(
146149
long = "bazel",
147150
help = "Run in Bazel mode (temporary, will be removed)"
@@ -298,6 +301,7 @@ fn main() -> anyhow::Result<()> {
298301
&prelude,
299302
dialect,
300303
globals,
304+
args.eager,
301305
)?;
302306
return Ok(());
303307
}
@@ -313,6 +317,7 @@ fn main() -> anyhow::Result<()> {
313317
is_interactive,
314318
dialect,
315319
globals,
320+
args.eager,
316321
)?;
317322

318323
if args.lsp {

0 commit comments

Comments
 (0)