Skip to content

Commit

Permalink
Language Server
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWhiting committed Jul 25, 2023
1 parent b312286 commit e3c0fd4
Show file tree
Hide file tree
Showing 36 changed files with 2,392 additions and 504 deletions.
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
22 changes: 21 additions & 1 deletion 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.35.2.
--
-- see: https://github.com/sol/hpack

Expand Down Expand Up @@ -92,6 +92,16 @@ executable koka
Kind.Repr
Kind.Synonym
Kind.Unify
LanguageServer.Conversions
LanguageServer.Handler.Completion
LanguageServer.Handler.Definition
LanguageServer.Handler.DocumentSymbol
LanguageServer.Handler.Hover
LanguageServer.Handler.Initialized
LanguageServer.Handler.TextDocument
LanguageServer.Handlers
LanguageServer.Monad
LanguageServer.Run
Lib.JSON
Lib.PPrint
Lib.Printer
Expand Down Expand Up @@ -144,10 +154,15 @@ executable koka
array
, base >=4.9
, bytestring
, co-log-core
, containers
, directory
, isocline >=1.0.6
, lens
, lsp
, mtl
, network
, network-simple
, parsec
, process
, text
Expand All @@ -170,6 +185,7 @@ test-suite koka-test
array
, base >=4.9
, bytestring
, co-log-core
, containers
, directory
, extra
Expand All @@ -178,7 +194,11 @@ test-suite koka-test
, hspec-core
, isocline >=1.0.6
, json
, lens
, lsp
, mtl
, network
, network-simple
, parsec
, process
, regex-compat >=0.95.2.1
Expand Down
5 changes: 5 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ dependencies:
- array
- bytestring
- containers
- co-log-core
- directory
- lens
- lsp
- mtl
- parsec
- process
- text
- time
- network-simple
- network
- isocline >= 1.0.6

executables:
Expand Down
59 changes: 56 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,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 @@ -315,6 +312,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 @@ -457,6 +465,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
2 changes: 1 addition & 1 deletion src/Common/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-----------------------------------------------------------------------------
module Common.Error( Error, ErrorMessage(..), errorMsg, ok
, catchError, checkError, warningMsg, addWarnings, ignoreWarnings
, ppErrorMessage, errorWarning ) where
, ppErrorMessage, errorWarning, prettyWarnings ) where

import Control.Monad
import Control.Monad.Fail
Expand Down
6 changes: 5 additions & 1 deletion src/Common/Range.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Common.Range
( Pos, makePos, minPos, maxPos, posColumn, posLine, posOfs
, posMove8, posMoves8, posNull
, Range, showFullRange
, makeRange, rangeNull, combineRange, rangeEnd, rangeStart
, makeRange, rangeNull, combineRange, rangeEnd, rangeStart, rangeLength
, Ranged( getRange ), combineRanged
, combineRangeds, combineRanges, extendRange
, Source(Source,sourceName, sourceBString), sourceText, sourceFromRange
Expand Down Expand Up @@ -275,6 +275,10 @@ rangeStart (Range p1 p2) = p1
rangeEnd :: Range -> Pos
rangeEnd (Range p1 p2) = p2

-- | Return the length of a range
rangeLength :: Range -> Int
rangeLength (Range p1 p2) = posOfs p2 - posOfs p1

-- | Return the source of a range
rangeSource :: Range -> Source
rangeSource = posSource . rangeStart
Expand Down
3 changes: 2 additions & 1 deletion src/Common/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ isHandlerNormal _ = False


data OperationSort
= OpVal | OpFun | OpExcept | OpControlRaw | OpControl
= OpVal | OpFun | OpExcept | OpControlRaw | OpControl | OpControlErr
deriving (Eq,Ord)

instance Show OperationSort where
Expand All @@ -157,6 +157,7 @@ instance Show OperationSort where
OpExcept -> "brk"
OpControl -> "ctl"
OpControlRaw -> "rawctl"
OpControlErr -> ""

readOperationSort :: String -> Maybe OperationSort
readOperationSort s
Expand Down
Loading

0 comments on commit e3c0fd4

Please sign in to comment.