Skip to content

Commit

Permalink
[flow] Support component syntax components in document symbol
Browse files Browse the repository at this point in the history
Summary: Changelog: [ide] Component-syntax components will now show up in document symbols

Reviewed By: panagosg7

Differential Revision: D70104859

fbshipit-source-id: 53ac1278399b0f913a9e61a93935946111afa820
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Feb 24, 2025
1 parent 265950d commit 996cfea
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions newtests/lsp/documentSymbol/_flowconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[options]
component_syntax=true
exact_by_default=false
enums=true
3 changes: 3 additions & 0 deletions newtests/lsp/documentSymbol/stuff.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ function loops() {
for (let j in { x: 123 }) {}
for (let k of [1, 2, 3]) {}
}

component ComponentFoo() {}
declare component ComponentBar();
82 changes: 82 additions & 0 deletions newtests/lsp/documentSymbol/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,54 @@ module.exports = (suite(
},
],
},
{
name: 'ComponentFoo',
kind: 12,
range: {
start: {
line: 135,
character: 0,
},
end: {
line: 135,
character: 27,
},
},
selectionRange: {
start: {
line: 135,
character: 10,
},
end: {
line: 135,
character: 22,
},
},
},
{
name: 'ComponentBar',
kind: 12,
range: {
start: {
line: 136,
character: 0,
},
end: {
line: 136,
character: 33,
},
},
selectionRange: {
start: {
line: 136,
character: 18,
},
end: {
line: 136,
character: 30,
},
},
},
],
},
],
Expand Down Expand Up @@ -3535,6 +3583,40 @@ module.exports = (suite(
},
containerName: 'loops',
},
{
name: 'ComponentFoo',
kind: 12,
location: {
uri: '<PLACEHOLDER_PROJECT_URL>/stuff.js',
range: {
start: {
line: 135,
character: 0,
},
end: {
line: 135,
character: 27,
},
},
},
},
{
name: 'ComponentBar',
kind: 12,
location: {
uri: '<PLACEHOLDER_PROJECT_URL>/stuff.js',
range: {
start: {
line: 136,
character: 0,
},
end: {
line: 136,
character: 33,
},
},
},
},
],
},
],
Expand Down
26 changes: 26 additions & 0 deletions src/lsp/documentSymbolProvider.ml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,32 @@ class visitor =
this#add_with_children ~loc ~selection ~name ~kind (super#class_expression class_loc) cls
| `Normal -> this#add_with_children ~loc ~selection ~name ~kind super#expression value

method! component_declaration loc component =
let (name, selection) =
Base.Option.value
~default:("<component>", loc)
(name_and_loc_of_identifier component.Ast.Statement.ComponentDeclaration.id)
in
let k = Lsp.SymbolInformation.Function in
this#add_with_children
~loc
~selection
~name
~kind:k
(super#component_declaration loc)
component;
component

method! declare_component loc component =
let (name, selection) =
Base.Option.value
~default:("<component>", loc)
(name_and_loc_of_identifier component.Ast.Statement.DeclareComponent.id)
in
let k = Lsp.SymbolInformation.Function in
this#add_with_children ~loc ~selection ~name ~kind:k (super#declare_component loc) component;
component

method class_decl_or_expr f loc (cls : (Loc.t, Loc.t) Ast.Class.t) =
let open Ast.Class in
let { id; _ } = cls in
Expand Down

0 comments on commit 996cfea

Please sign in to comment.