Skip to content

Commit

Permalink
feat(lang): Add sticky headers and code lens for PHP (#1960)
Browse files Browse the repository at this point in the history
* feat(lang): Add sticky headers and code lens for PHP

* doc(lens): Add doc strings for how code lenses are built
  • Loading branch information
claytonrcarter committed Jan 11, 2023
1 parent 3e5dc32 commit 1c57875
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [#1856](https://github.com/lapce/lapce/pull/1856): Highlight git/VCS modified files in explorer, palette, and buffer tabs
- [#1574](https://github.com/lapce/lapce/pull/1574): Panel sections can be expanded/collapsed
- [#1938](https://github.com/lapce/lapce/pull/1938): Use dropdown for theme selection in settings
- [#1960](https://github.com/lapce/lapce/pull/1960): Add sticky headers and code lens for PHP

### Bug Fixes
- [#1911](https://github.com/lapce/lapce/pull/1911): Fix movement on selections with left/right arrow keys
Expand Down
48 changes: 43 additions & 5 deletions lapce-core/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ struct SyntaxProperties {
comment: &'static str,
/// The indent unit. " " for javascript, " " for rust, for example.
indent: &'static str,
/// TODO: someone more knowledgeable please describe what the two lists are.
/// Anyway, the second element of the tuple is a "ignore list". See
/// `walk_tree`. If unsure, use `DEFAULT_CODE_LENS_LIST` and
/// Lists of tree-sitter node types that control how code lenses are built.
/// The first is a list of nodes that should be traversed and included in
/// the lens, along with thier children. The second is a list of nodes that
/// should be excluded from the lens, though they will still be traversed.
/// See `walk_tree` for more details.
///
/// The tree-sitter playground may be useful when creating these lists:
/// https://tree-sitter.github.io/tree-sitter/playground
///
/// If unsure, use `DEFAULT_CODE_LENS_LIST` and
/// `DEFAULT_CODE_LENS_IGNORE_LIST`.
code_lens: (&'static [&'static str], &'static [&'static str]),
/// the tree sitter tag names that can be put in sticky headers
Expand Down Expand Up @@ -694,8 +701,35 @@ const LANGUAGES: &[SyntaxProperties] = &[
injection: Some(tree_sitter_php::INJECTIONS_QUERY),
comment: "//",
indent: " ",
code_lens: (DEFAULT_CODE_LENS_LIST, DEFAULT_CODE_LENS_IGNORE_LIST),
sticky_headers: &[],
code_lens: (
&[
"program",
"class_declaration",
"trait_declaration",
"interface_declaration",
"declaration_list",
"method_declaration",
"function_declaration",
],
&[
"program",
"php_tag",
"comment",
"namespace_definition",
"namespace_use_declaration",
"use_declaration",
"const_declaration",
"property_declaration",
"expression_statement",
],
),
sticky_headers: &[
"class_declaration",
"trait_declaration",
"interface_declaration",
"method_declaration",
"function_declaration",
],
extensions: &["php"],
},
#[cfg(feature = "lang-prisma")]
Expand Down Expand Up @@ -1044,6 +1078,10 @@ impl LapceLanguage {
}
}

/// Walk an AST and determine which lines to include in the code lens.
///
/// Node types listed in `list` will be walked, along with their children. All
/// nodes encountered will be included, unless they are listed in `ignore_list`.
fn walk_tree(
cursor: &mut TreeCursor,
normal_lines: &mut HashSet<usize>,
Expand Down

0 comments on commit 1c57875

Please sign in to comment.