Skip to content

Commit

Permalink
Open up visibility of starlark-syntax
Browse files Browse the repository at this point in the history
Summary:
# Goal

One of the wins from having this as a separate extension is that we can customize the lint warnings for Sandcastle-specific codesmells.

# This diff

This is an RFC/POC for a very simple one: no `entry_point` called outside of the top-level.

To get this to work, I needed to make some changes to the visibility of things. See [this discussion](https://fb.workplace.com/groups/starlark/permalink/1547671819254974/) for context -- but *tldr;* is that a lot of the AST-manipulation/traversal stuff in `starlark_syntax` is hidden away.

The changes I made are to:
- Expose a `statements()` getter on `AstModule`
- Remove the visibility rule on `starlark_syntax`, making it available for use outside of `starlark-rust`

These were both needed because I want to specifically manipulate the Starlark AST (ie. traverse things the bodies of function definitions). See how I use them in D67765416.

The hope is that these changes are amenable for the maintainers for `starlark-rust` --
obviously I'm open to suggestions for other approaches as well.

Reviewed By: JakobDegen

Differential Revision: D67611206

fbshipit-source-id: d577f1886ff190d191f3c55022f9d485f6eb03be
  • Loading branch information
Jack Pan authored and facebook-github-bot committed Jan 3, 2025
1 parent 78169ab commit 5c8ca2d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 3 deletions.
1 change: 0 additions & 1 deletion starlark/src/analysis/find_call_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use starlark_syntax::syntax::ast::Argument;
use starlark_syntax::syntax::ast::AstExpr;
use starlark_syntax::syntax::ast::AstLiteral;
use starlark_syntax::syntax::ast::Expr;
use starlark_syntax::syntax::module::AstModuleFields;

use crate::codemap::Span;
use crate::codemap::Spanned;
Expand Down
1 change: 1 addition & 0 deletions starlark/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
pub use starlark_syntax::dialect::Dialect;
pub use starlark_syntax::dialect::DialectTypes;
pub use starlark_syntax::syntax::ast;
pub use starlark_syntax::syntax::AstLoad;
pub use starlark_syntax::syntax::AstModule;
1 change: 0 additions & 1 deletion starlark_lsp/src/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use starlark_syntax::syntax::ast::ForP;
use starlark_syntax::syntax::ast::IdentP;
use starlark_syntax::syntax::ast::LambdaP;
use starlark_syntax::syntax::ast::Stmt;
use starlark_syntax::syntax::module::AstModuleFields;

#[derive(Debug, Clone, Eq, PartialEq)]
pub(crate) enum Assigner {
Expand Down
1 change: 0 additions & 1 deletion starlark_lsp/src/loaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use dupe::Dupe;
use starlark::syntax::AstModule;
use starlark_syntax::syntax::ast::StmtP;
use starlark_syntax::syntax::module::AstModuleFields;
use starlark_syntax::syntax::top_level_stmts::top_level_stmts;

/// A loaded symbol. Returned from [`AstModule::loaded_symbols`].
Expand Down
5 changes: 5 additions & 0 deletions starlark_syntax/src/syntax/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ impl AstModule {
self.codemap.file_span(x)
}

/// Get back the AST statement for the module
pub fn statement(&self) -> &AstStmt {
&self.statement
}

/// Locations where statements occur.
pub fn stmt_locations(&self) -> Vec<FileSpan> {
fn go(x: &AstStmt, codemap: &CodeMap, res: &mut Vec<FileSpan>) {
Expand Down

0 comments on commit 5c8ca2d

Please sign in to comment.