Skip to content
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

Language server #346

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5fd92be
Language Server
TimWhiting Dec 5, 2023
db0bad6
better type environment for pretty
TimWhiting Dec 5, 2023
a0c0d23
update logo colors
daanx Dec 5, 2023
80a2d30
fix normalization of paths using realPath to get correct capitalizati…
TimWhiting Dec 5, 2023
489843e
fix long paths on hover
TimWhiting Dec 9, 2023
a6a0d8b
additional normalization of import paths, and moduleSourcePaths
TimWhiting Dec 9, 2023
51c53ca
fix a bunch of things and add test runners
TimWhiting Dec 10, 2023
59f4bc9
remove some trace statements
TimWhiting Dec 10, 2023
c549db3
allow loadedModules of loaded since I'm keeping each loaded state sep…
TimWhiting Dec 10, 2023
fc0f566
update comment
TimWhiting Dec 10, 2023
0b8e81a
remove additional trace
TimWhiting Dec 10, 2023
957e39c
a bit more strict
TimWhiting Dec 11, 2023
e151de2
more precise diagnostics (correct files and clearing / persisting at …
TimWhiting Dec 12, 2023
3707e24
Add inlay types and fix buffering of stdout
TimWhiting Dec 12, 2023
29129fc
fix buffering
TimWhiting Dec 12, 2023
d4bb2f3
clean up a few small things with the extension
TimWhiting Dec 13, 2023
5b8e40f
update test function regex
TimWhiting Dec 13, 2023
5c16595
Create a separate main function that doesn't include language server.…
TimWhiting Dec 15, 2023
dba7b7d
fix error union
TimWhiting Dec 15, 2023
1eb0c86
add support for running example* functions and reorganize vscode exte…
TimWhiting Dec 15, 2023
b776bc2
add folding handler
TimWhiting Dec 15, 2023
935288b
better hover colors and a few other fixes
TimWhiting Dec 15, 2023
6a4e02e
fix diagnostic issue
TimWhiting Dec 15, 2023
eba708f
update diagnostics
TimWhiting Dec 15, 2023
d20336b
rearrange dependencies
TimWhiting Dec 15, 2023
8fc7229
add config option on debug
TimWhiting Dec 16, 2023
64021fd
fix path
TimWhiting Dec 16, 2023
436ded8
fix exit result
TimWhiting Dec 16, 2023
4d506af
fix program arguments, recompiling on flags changed, and adding relea…
TimWhiting Dec 16, 2023
2f742c3
move app and lang-server under src/Main
daanx Dec 16, 2023
dbd9146
add readmes
daanx Dec 16, 2023
a80bc58
rename some koka language server setting; update readme, update cente…
daanx Dec 16, 2023
354968a
update extension
TimWhiting Dec 16, 2023
96cdcdc
update readme
TimWhiting Dec 16, 2023
c607f91
update code lens description and tooltip
daanx Dec 16, 2023
77a7aa8
Merge branch 'lang-server2.0' of https://github.com/TimWhiting/koka i…
daanx Dec 16, 2023
13b4b8d
fix readme to reflect renaming
TimWhiting Dec 16, 2023
04c2fba
fix custom sdk path
TimWhiting Dec 16, 2023
d4a27cd
Merge branch 'lang-server2.0' of https://github.com/TimWhiting/koka i…
daanx Dec 16, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
.DS_Store
.vs/
.vscode/
.koka/
node_modules/
out/
bundle/
Expand All @@ -30,3 +29,5 @@ test.kk
/*.cmake
bench
test/bench
.koka
scratch
240 changes: 120 additions & 120 deletions LICENSE

Large diffs are not rendered by default.

75 changes: 70 additions & 5 deletions koka.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.35.0.
-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack

Expand All @@ -21,9 +21,8 @@ source-repository head
type: git
location: https://github.com/koka-lang/koka

executable koka
main-is: Main.hs
other-modules:
library
exposed-modules:
Backend.C.Box
Backend.C.FromCore
Backend.C.Parc
Expand Down Expand Up @@ -125,14 +124,15 @@ executable koka
Platform.ReadLine
Platform.Runtime
Platform.Var
other-modules:
Paths_koka
hs-source-dirs:
src
src/Platform/cpp
other-extensions:
CPP
OverloadedStrings
ghc-options: -rtsopts -j8
ghc-options: -j8 -O2
cpp-options: -DKOKA_MAIN="koka" -DKOKA_VARIANT="release" -DKOKA_VERSION="2.4.3" -DREADLINE=0
include-dirs:
src/Platform/cpp/Platform
Expand All @@ -158,6 +158,71 @@ executable koka
if os(darwin)
cpp-options: -DDARWIN

executable koka
main-is: Main.hs
other-modules:
LanguageServer.Conversions
LanguageServer.Handler.Commands
LanguageServer.Handler.Completion
LanguageServer.Handler.Definition
LanguageServer.Handler.DocumentSymbol
LanguageServer.Handler.Folding
LanguageServer.Handler.Hover
LanguageServer.Handler.InlayHints
LanguageServer.Handler.TextDocument
LanguageServer.Handlers
LanguageServer.Monad
LanguageServer.Run
Paths_koka
hs-source-dirs:
src/Main/langserver
ghc-options: -rtsopts -j8 -O2 -threaded "-with-rtsopts=-N8"
build-depends:
aeson
, array
, async
, base >=4.9
, bytestring
, co-log-core
, containers
, directory
, isocline >=1.0.6
, koka
, lens
, lsp
, mtl
, network
, network-simple
, parsec
, process
, stm
, text
, text-rope
, time
default-language: Haskell2010

executable koka-plain
main-is: Main.hs
other-modules:
Paths_koka
hs-source-dirs:
src/Main/plain
ghc-options: -rtsopts -j8 -O2 -threaded "-with-rtsopts=-N8"
build-depends:
array
, base >=4.9
, bytestring
, containers
, directory
, isocline >=1.0.6
, koka
, mtl
, parsec
, process
, text
, time
default-language: Haskell2010

test-suite koka-test
type: exitcode-stdio-1.0
main-is: Spec.hs
Expand Down
83 changes: 57 additions & 26 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# - util/install.bat
# - util/Dockerfile
# - util/minbuild
# - support/vscode/koka.language-koka/src/workspace.ts
# - support/vscode/koka.language-koka/package.json

name: koka
version: 2.4.3
Expand All @@ -29,37 +31,66 @@ dependencies:
- text
- time
- isocline >= 1.0.6


library:
other-extensions:
- CPP
- OverloadedStrings
source-dirs:
- src
- src/Platform/cpp
c-sources:
- src/Platform/cpp/Platform/cconsole.c
include-dirs:
- src/Platform/cpp/Platform
build-tools:
- alex
ghc-options:
- -j8
- -O2
cpp-options:
- -DKOKA_MAIN="koka"
- -DKOKA_VARIANT="release"
- -DKOKA_VERSION="2.4.3"
- -DREADLINE=0 # 1:getline, 2:readline, 3:haskeline, or 0:isocline
when:
- condition: os(windows)
cpp-options: -DWINDOWS
- condition: os(darwin)
cpp-options: -DDARWIN

executables:
koka:
main: Main.hs
# source-dirs: app
# dependencies: koka
other-extensions:
- CPP
- OverloadedStrings
source-dirs:
- src
- src/Platform/cpp
c-sources:
- src/Platform/cpp/Platform/cconsole.c
include-dirs:
- src/Platform/cpp/Platform
build-tools:
- alex
source-dirs: src/Main/langserver
dependencies:
- aeson
- async
- co-log-core
- koka
- lens
- lsp
- network-simple
- network
- text-rope
- stm
ghc-options:
- -rtsopts
- -rtsopts
- -j8
cpp-options:
- -DKOKA_MAIN="koka"
- -DKOKA_VARIANT="release"
- -DKOKA_VERSION="2.4.3"
- -DREADLINE=0 # 1:getline, 2:readline, 3:haskeline, or 0:isocline
when:
- condition: os(windows)
cpp-options: -DWINDOWS
- condition: os(darwin)
cpp-options: -DDARWIN
- -O2
- -threaded
- '"-with-rtsopts=-N8"'

koka-plain:
main: Main.hs
source-dirs: src/Main/plain
dependencies: koka
ghc-options:
- -rtsopts
- -j8
- -O2
- -threaded
- '"-with-rtsopts=-N8"'

tests:
koka-test:
Expand Down
59 changes: 56 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ More advanced projects:
* [x] Update the JavaScript backend to 1) use modern modules instead of amdefine, 2) use the new bigints instead of
bigint.js, and 3) add support for int64. (landed in the `dev` branch)
* [x] Port `std/text/regex` from v1 (using PCRE)
* [ ] A language server for Visual Studio Code and Atom. Koka can already generate a
typed [range map](src/Syntax/RangeMap.hs) so this should be managable. Partially done: see PR #100 (by @fwcd) -- it just
needs work on packaging it to make it easy to build and install as part of the Koka installer.
* [ ] Package management of Koka modules.
* [x] Compile to WASM (using emscripten on the current C backend)
* [ ] Improve compilation of local state to use local variables directly (in C) without allocation. Tricky though due to multiple resumptions.
Expand Down Expand Up @@ -318,6 +315,17 @@ The following is the immediate todo list to be completed in the coming months:
* [ ] Port `std/async` (using `libuv`).
* [ ] Proper overloading with (a form of) type classes. (in design phase).

LSP Related Tasks:
* [ ] Generate completions for effect handlers (with empty bodies of all the functions)
* [ ] Generate show / (==) for datatypes
* [ ] Find References
* [ ] Generate Type Annotations

Extension Related Tasks:

VSCode:
* [ ] Add support for debugging an executable

Contact me if you are interested in tackling some of these :-)

# Build Notes
Expand Down Expand Up @@ -460,6 +468,51 @@ $ out\v2.0.5\cl-release\test_bench_koka_rbtree --kktime
info: elapsed: 1.483s, user: 1.484s, sys: 0.000s, rss: 164mb
```

## Language Server

The language server is started by running the koka compilter with the --language-server flag
and then connecting to it with a client that supports the Language Server Protocol (LSP)

For example, using VSCode, install the Koka extension or run the extension debug configuration in the project.
Open up a folder and start editing `.kk` files. (The extension finds the koka executable and then automatically starts the language server for you).

The VSCode extension searches in the following locations for the koka executable:
- A koka development environment in ~/koka
- A local install ~/.local/bin
- The PATH environment variable

To specify the command to start the language server manually, such as to provide additional flags to the koka compiler override the `koka.languageServer.command` VSCode setting.
To specify the current working directory to run the compiler from use the `koka.languageServer.cwd` setting. If there are problems with the language server, you can enable the `koka.languageServer.trace.server` setting to see the language server logs, or turn off the language server by setting the `koka.languageServer.enable` setting to `false`.

To develop the language server, you can use this VSCode debug configuration (add the configuration to .vscode/launch.json).

```json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"request": "launch",
"type": "extensionHost",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/support/vscode/koka.language-koka"
],
"outFiles": [
"${workspaceFolder}/support/vscode/koka.language-koka/out/**/*.js"
]
}
]
}
```

- Run `npm install && npm run build` in the `support/vscode/koka.language-koka` directory
- Update the LSP server in the `src/LanguageServer` directory with your changes
- Run `stack build`
- Restart the debug configuration and make sure a notification pops up that you are using the development version of the koka sdk

## Older Release Notes

* `v2.1.9`, 2021-06-23: initial support for cross-module specialization (by Steven Fontanella).
Expand Down
12 changes: 9 additions & 3 deletions samples/basic/fibonacci.kk
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
module fibonacci

pub fun main()
pub fun mainx()
val n = 10000
println("The " ++ n.show ++ "th fibonacci number is " ++ fibonacci(10000).show)


fun fibonacci(n : int) : div int
fun fibonacci(n : int) : div int
fib(n, 0, 1)


fun fib(n : int, x1 : int, x2 : int) : div int
fun fib(n : int, x1 : int, x2 : int) : div int
if n<=0 then x1 else fib(n - 1, x2, x1+x2)

pub fun testx()
fibonacci(100).println


pub fun test2()
fibonacci(1000).println
8 changes: 4 additions & 4 deletions samples/basic/rbtree.kk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type color
type tree<a>
Node(color : color, left : tree<a>, key : int, value : a, right : tree<a>)
Leaf


fun is-red(t : tree<a>) : bool
match t
Expand All @@ -32,7 +32,7 @@ fun balance-left(l :tree<a>, k : int, v : a, r : tree<a>) : tree<a>
Node(_, lx, kx, vx, rx)
-> Node(Black, Node(Red, lx, kx, vx, rx), k, v, r)
Leaf -> Leaf



fun balance-right(l : tree<a>, k : int, v : a, r : tree<a>) : tree<a>
Expand All @@ -44,7 +44,7 @@ fun balance-right(l : tree<a>, k : int, v : a, r : tree<a>) : tree<a>
Node(_, lx, kx, vx, rx)
-> Node(Black, l, k, v, Node(Red, lx, kx, vx, rx))
Leaf -> Leaf


fun ins(t : tree<a>, k : int, v : a) : tree<a>
match t
Expand Down Expand Up @@ -88,7 +88,7 @@ fun make-tree(n : int) : tree<bool>


// Count the nodes with `True` values.
fun count( t : tree<bool> ) : int
fun count( t : tree<bool> ) : int
t.fold(0) fn(k,v,r)
if v then r + 1 else r

Expand Down
1 change: 1 addition & 0 deletions src/Backend/C/FromCore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2663,6 +2663,7 @@ reserved
, "instanceof"
, "new"
, "return"
, "register"
, "switch"
, "this"
, "throw"
Expand Down
Loading