Skip to content

Ws symbols (continues from #510) #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-including-additional-values-into-combinations
include:
- os: macos-latest
build: eval $(opam env) && cd analysis && make test
build: eval $(opam env) && cd analysis && make test -j
artifact-folder: darwin
- os: ubuntu-18.04
build: eval $(opam env) && cd analysis && make test
build: eval $(opam env) && cd analysis && make test -j
artifact-folder: linux
- os: windows-latest
build: "cd analysis && & $env:CYGWIN_ROOT\\bin\\ocaml-env exec -- make test"
build: "cd analysis && & $env:CYGWIN_ROOT\\bin\\ocaml-env exec -- make test -j"
artifact-folder: win32

runs-on: ${{matrix.os}}
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
out
node_modules
examples/*/lib
analysis/tests/lib
analysis/tests/.bsb.lock
analysis/tests/**/*/lib
analysis/tests/*/.bsb.lock
analysis/_build
analysis/tests/.merlin
analysis/tests/**/*/.merlin
analysis/rescript-editor-analysis.exe

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

#### :rocket: New Feature

- Add workspace Symbols
- Inlay Hints (experimetal). `rescript.settings.inlayHints.enable: true`. Turned off by default.
- Code Lenses for functions (experimetal). `rescript.settings.codeLens: true`. Turned off by default.
- Markdown code blocks tagged as `rescript` now get basic syntax highlighting.

#### :bug: Bug Fix

- Fix Incorrect rendering on the right of `external`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The only 2 themes we don't (and can't) support, due to their lack of coloring, a
- Find references.
- Rename.
- Inlay Hints
- Workspace Symbols
- Snippets to ease a few syntaxes:
- `external` features such as `@bs.module` and `@bs.val`
- `try`, `for`, etc.
Expand Down
10 changes: 8 additions & 2 deletions analysis/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ dce: build-analysis-binary
format:
dune build @fmt --auto-promote

test-analysis-binary: build-analysis-binary
build-tests:
make -C tests build

install-reanalyze: install-reanalyze
make -C reanalyze install

test-analysis-binary: build-analysis-binary build-tests
make -C tests test

test-reanalyze: build-analysis-binary
test-reanalyze: build-analysis-binary build-reanalyze
make -C reanalyze test

test: test-analysis-binary test-reanalyze
Expand Down
26 changes: 23 additions & 3 deletions analysis/reanalyze/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
SHELL = /bin/bash

build:
install-deadcode:
make -C examples/deadcode install

install-termination:
make -C examples/termination install

install: install-deadcode install-termination

build-deadcode: install-deadcode
make -C examples/deadcode build

build-termination: install-termination
make -C examples/termination build

test:
build: build-deadcode build-termination

test-deadcode: build-deadcode
make -C examples/deadcode test

test-termination: build-termination
make -C examples/termination test

clean:
test: test-deadcode test-termination

clean-deadcode:
make -C examples/deadcode clean

clean-termination:
make -C examples/termination clean

clean: clean-deadcode clean-termination

.DEFAULT_GOAL := build

.PHONY: build clean clean test
10 changes: 6 additions & 4 deletions analysis/reanalyze/examples/deadcode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ SHELL = /bin/bash
node_modules/.bin/rescript:
npm install

build: node_modules/.bin/rescript
install: node_modules/.bin/rescript

build: install
node_modules/.bin/rescript

test: build node_modules/.bin/rescript
test: build
./test.sh

clean:
rm -r node_modules lib
rm -rf node_modules lib

.DEFAULT_GOAL := build

.PHONY: build clean test
.PHONY: build clean test install
10 changes: 6 additions & 4 deletions analysis/reanalyze/examples/termination/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ SHELL = /bin/bash
node_modules/.bin/rescript:
npm install

build: node_modules/.bin/rescript
install: node_modules/.bin/rescript

build: install
node_modules/.bin/rescript

test: build node_modules/.bin/rescript
test: build
./test.sh

clean:
rm -r node_modules lib
rm -rf node_modules lib

.DEFAULT_GOAL := build

.PHONY: build clean test
.PHONY: build clean test install
8 changes: 7 additions & 1 deletion analysis/src/Cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ API examples:
./rescript-editor-analysis.exe definition src/MyFile.res 9 3
./rescript-editor-analysis.exe typeDefinition src/MyFile.res 9 3
./rescript-editor-analysis.exe documentSymbol src/Foo.res
./rescript-editor-analysis.exe workspaceSymbols src/
./rescript-editor-analysis.exe hover src/MyFile.res 10 2
./rescript-editor-analysis.exe references src/MyFile.res 10 2
./rescript-editor-analysis.exe rename src/MyFile.res 10 2 foo
Expand Down Expand Up @@ -39,6 +40,10 @@ Options:

./rescript-editor-analysis.exe documentSymbol src/MyFile.res

workspaceSymbols: get all symbols in directory src/

./rescript-editor-analysis.exe workspaceSymbols src/

hover: get inferred type for MyFile.res at line 10 column 2:

./rescript-editor-analysis.exe hover src/MyFile.res 10 2
Expand Down Expand Up @@ -94,7 +99,8 @@ let main () =
Commands.typeDefinition ~path
~pos:(int_of_string line, int_of_string col)
~debug:false
| [_; "documentSymbol"; path] -> DocumentSymbol.command ~path
| [_; "documentSymbol"; path] -> Commands.documentSymbol ~path
| [_; "workspaceSymbols"; dir] -> Commands.workspaceSymbols ~dir
| [_; "hover"; path; line; col; currentFile] ->
Commands.hover ~path
~pos:(int_of_string line, int_of_string col)
Expand Down
21 changes: 19 additions & 2 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,27 @@ let format ~path =
let diagnosticSyntax ~path =
print_endline (Diagnostics.document_syntax ~path |> Protocol.array)

let documentSymbol ~path =
Symbols.document ~path
|> List.map Protocol.stringifyDocumentSymbolItem
|> Protocol.array |> print_endline

let workspaceSymbols ~dir =
print_endline
(match Symbols.workspace ~dir with
| Some symbol -> symbol
| None -> Protocol.null)

let test ~path =
Uri.stripPath := true;
match Files.readFile path with
| None -> assert false
| None -> (
(* Test for workspaces/directory *)
let nameTest = Filename.basename(path) in
match nameTest with
| "workspaceSymbols" -> workspaceSymbols ~dir:path
| _ -> assert false
)
| Some text ->
let lines = text |> String.split_on_char '\n' in
let processLine i line =
Expand Down Expand Up @@ -327,7 +344,7 @@ let test ~path =
DceCommand.command ()
| "doc" ->
print_endline ("DocumentSymbol " ^ path);
DocumentSymbol.command ~path
documentSymbol ~path
| "hig" ->
print_endline ("Highlight " ^ path);
SemanticTokens.command ~debug:true
Expand Down
3 changes: 1 addition & 2 deletions analysis/src/Hint.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
open SharedTypes

type inlayHintKind = Type | Parameter
type inlayHintKind = Type
let inlayKindToNumber = function
| Type -> 1
| Parameter -> 2

let locItemToTypeHint ~full:{file; package} locItem =
match locItem.locType with
Expand Down
57 changes: 40 additions & 17 deletions analysis/src/DocumentSymbol.ml → analysis/src/Symbols.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let kindNumber = function
| EnumMember -> 22
| TypeParameter -> 26

let command ~path =
let document ~path =
let symbols = ref [] in
let rec exprKind (exp : Parsetree.expression) =
match exp.pexp_desc with
Expand Down Expand Up @@ -134,19 +134,42 @@ let command ~path =
let parser = Res_driver.parsingEngine.parseInterface ~forPrinter:false in
let {Res_driver.parsetree = signature} = parser ~filename:path in
iterator.signature iterator signature |> ignore);
let result =
!symbols
|> List.rev_map (fun (name, loc, kind) ->
Protocol.stringifyDocumentSymbolItem
{
name;
location =
{
uri = Uri.toString (Uri.fromPath path);
range = Utils.cmtLocToRange loc;
};
kind = kindNumber kind;
})
|> String.concat ",\n"
in
print_endline ("[\n" ^ result ^ "\n]")
!symbols
|> List.rev_map (fun (name, loc, kind) ->
let symbol : Protocol.documentSymbolItem =
{
name;
location =
{
uri = Uri.toString (Uri.fromPath path);
range = Utils.cmtLocToRange loc;
};
kind = kindNumber kind;
}
in
symbol)

let workspace ~dir =
let open FindFiles in
let bsconfig = dir /+ "bsconfig.json" in
match Files.readFile bsconfig with
| None -> None
| Some text -> (
match Json.parse text with
| None -> None
| Some inner ->
let sourceDirectories =
getSourceDirectories ~includeDev:false ~baseDir:dir inner
in
let result =
sourceDirectories
|> List.map (fun srcDir ->
Files.readDirectory (dir /+ srcDir)
|> List.map (fun path -> dir /+ srcDir /+ path)
|> List.filter isSourceFile |> filterDuplicates)
|> List.flatten
|> List.map (fun path ->
document ~path |> List.map Protocol.stringifyDocumentSymbolItem)
|> List.flatten |> Protocol.array
in
Some result)
21 changes: 16 additions & 5 deletions analysis/tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
SHELL = /bin/bash

node_modules/.bin/rescript:
npm install
buildDocument:
make -C document build

build: node_modules/.bin/rescript
node_modules/.bin/rescript
buildWorkspaceSymbols:
make -C workspaceSymbols build

build: buildDocument buildWorkspaceSymbols

test: build
./test.sh

install-document:
make -C document install

install-workspaceSymbols:
make -C workspaceSymbols install

install: install-document install-workspaceSymbols

clean:
rm -r node_modules lib
make -C document clean
make -C workspaceSymbols clean

.DEFAULT_GOAL := test

Expand Down
14 changes: 14 additions & 0 deletions analysis/tests/document/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SHELL = /bin/bash

build: node_modules/.bin/rescript
node_modules/.bin/rescript

install: node_modules/.bin/rescript

node_modules/.bin/rescript:
npm install

clean:
rm -rf node_modules lib

.PHONY: clean build
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Hover src/Auto.res 2:13
Hover document/src/Auto.res 2:13
{"contents": "```rescript\n(Belt.List.t<'a>, 'a => 'b) => Belt.List.t<'b>\n```\n\n\n Returns a new list with `f` applied to each element of `someList`.\n\n ```res example\n list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4}\n ```\n"}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Complete src/CompletePrioritize1.res 5:6
Complete document/src/CompletePrioritize1.res 5:6
posCursor:[5:6] posNoWhite:[5:5] Found expr:[5:3->0:-1]
Completable: Cpath Value[a]->
[{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Complete src/CompletePrioritize2.res 9:7
Complete document/src/CompletePrioritize2.res 9:7
posCursor:[9:7] posNoWhite:[9:6] Found expr:[9:3->0:-1]
Completable: Cpath Value[ax]->
[{
Expand All @@ -9,7 +9,7 @@ Completable: Cpath Value[ax]->
"documentation": null
}]

Complete src/CompletePrioritize2.res 12:5
Complete document/src/CompletePrioritize2.res 12:5
posCursor:[12:5] posNoWhite:[12:4] Found expr:[12:3->12:5]
Pexp_ident ax:[12:3->12:5]
Completable: Cpath Value[ax]
Expand Down
Loading