Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,17 @@ defmodule NextLS do
}, assign(lsp, root_uri: root_uri)}
end

def handle_request(%WorkspaceSymbol{params: %{query: _query}}, lsp) do
def handle_request(%WorkspaceSymbol{params: %{query: query}}, lsp) do
filter = fn sym ->
if query == "" do
true
else
to_string(sym) =~ query
end
end

symbols =
for %SymbolTable.Symbol{} = symbol <- SymbolTable.symbols(lsp.assigns.symbol_table) do
for %SymbolTable.Symbol{} = symbol <- SymbolTable.symbols(lsp.assigns.symbol_table), filter.(symbol.name) do
%SymbolInformation{
name: to_string(symbol.name),
kind: elixir_kind_to_lsp_kind(symbol.type),
Expand Down
60 changes: 60 additions & 0 deletions test/next_ls_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,64 @@ defmodule NextLSTest do
"name" => "Foo.CodeAction.NestedMod"
} in symbols
end

test "workspace symbols with query", %{client: client, cwd: cwd} do
assert :ok ==
notify(client, %{
method: "initialized",
jsonrpc: "2.0",
params: %{}
})

assert_notification "window/logMessage", %{"message" => "[NextLS] Runtime ready..."}
assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"}

request client, %{
method: "workspace/symbol",
id: 2,
jsonrpc: "2.0",
params: %{
query: "fo"
}
}

assert_result 2, symbols

assert [
%{
"kind" => 12,
"location" => %{
"range" => %{
"start" => %{
"line" => 3,
"character" => 0
},
"end" => %{
"line" => 3,
"character" => 0
}
},
"uri" => "file://#{cwd}/lib/bar.ex"
},
"name" => "foo"
},
%{
"kind" => 12,
"location" => %{
"range" => %{
"start" => %{
"line" => 4,
"character" => 0
},
"end" => %{
"line" => 4,
"character" => 0
}
},
"uri" => "file://#{cwd}/lib/code_action.ex"
},
"name" => "foo"
}
] == symbols
end
end