Skip to content

Commit

Permalink
Coalton LSP server
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwman committed Oct 25, 2024
1 parent cefb77d commit 6841cad
Show file tree
Hide file tree
Showing 36 changed files with 4,300 additions and 488 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
pull_request:
branches: [master]

jobs:
test:
name: ${{matrix.lisp}} on ${{matrix.os}}
strategy:
matrix:
lisp: [sbcl-bin] # only one cool lisp
os: [ubuntu-latest]
fail-fast: false
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install Roswell
shell: bash
env:
LISP: ${{matrix.lisp}}
run: curl -L https://raw.githubusercontent.com/roswell/roswell/master/scripts/install-for-ci.sh | sh -x

- name: Get Lisp info
continue-on-error: true
shell: bash
run: |
ros -e '(format t "Lisp: ~a ~a on ~a~%" (lisp-implementation-type) (lisp-implementation-version) (machine-type))'
ros -e '(ql:quickload "trivial-features" :silent t)' -e '(format t "Features: ~s~%" *features*)'
- name: Run tests
shell: bash
run: |
ros -e '(setf *debugger-hook* (lambda (&rest ignorable) (declare (ignore ignorable)) (uiop:quit -1)))' -e '(ql:quickload "coalton-lsp/tests")' -e '(unless (fiasco:all-tests) (uiop:quit -1))'
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*~
*#
*.fasl
.clj-kondo
.lsp
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Run unit tests, failing on the first error.

.PHONY: test
test:
sbcl --noinform --non-interactive \
--eval "(asdf:load-system :coalton-lsp/tests)" \
--eval "(fiasco:run-package-tests \
:packages '(:coalton-lsp/tests) \
:interactive nil)"
52 changes: 36 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
This directory contains the source code for an Emacs mode that supports
working with Coalton code.
This is an Emacs mode that supports working with Coalton. Most of the
logic is implemented as an LSP server.

## Requirements

This mode requires Emacs version > 29.1 because it relies on
tree-sitter. You can check that your copy of Emacs was built with
support for tree sitter by evaluating:
This mode has been developed using `eglot`, which is included with
Emacs since version 29. The mode can be installed with
`M-x package-install RET eglot RET` in Emacs 26.3 and later.

(treesit-available-p)
In addition to Coalton, the LSP server process depends on the
following Lisp libraries:

## Installation
- alexandria
- bordeaux-threads
- com.inuoe.jzon
- usocket

In your emacs init file (probably `~/.emacs.d/init.el` or `~/.emacs`),
add this directory to your load-path, and require the mode:
## Current Status

Supported LSP features:

- diagnostics: whenever a .coal file is saved, the contents are
compiled, and diagnostics are published to the client.

## Usage

In the Emacs init file (e.g. `~/.emacs.d/init.el`), add this
directory to the load-path, and require the mode:

;; Coalton

(add-to-list 'load-path "~/git/coalton-mode")
(require 'coalton-mode)

## Usage
Start the server in slime with:

There is an example file, `types.coal` in the `test/` directory.
SLIME 2.30.git
CL-USER> (asdf:load-system "coalton-lsp")
;; COALTON starting in development mode
;; COALTON starting with specializations enabled
;; COALTON starting with heuristic inlining disabled
;; COALTON will emit type annotations
T
CL-USER> (coalton-lsp::start-server)
;; :INFO coalton-mode: start #<SERVER 127.0.0.1:7887 {700D0A4333}>
#<COALTON-MODE::SERVER 127.0.0.1:7887 {700D0A4333}>

The first time you open a `.coal` file, Emacs will ask you to approve
the installation of a parser component:
In Emacs, open a .coal file (e.g. resources/fibonacci.coal), and
enable eglot mode:

tree-sitter-coalton is not installed. Clone, build and install it?

(Answer 'yes')
M-x eglot
17 changes: 17 additions & 0 deletions coalton-lsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh
#
# Run a Coalton server
#
# Usage:
#
# coalton-lsp [ port ]
#
# (port defaults to 7887)

port=${1:-7887}

sbcl \
--noinform \
--load coalton-lsp.asd \
--eval "(asdf:load-system \"coalton-lsp\")" \
--eval "(coalton-lsp:main :port ${port})"
39 changes: 39 additions & 0 deletions coalton-lsp.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(in-package :asdf-user)

(defsystem #:coalton-lsp
:depends-on (#:alexandria
#:bordeaux-threads
#:coalton
#:com.inuoe.jzon
#:usocket)
:pathname "src/"
:serial t
:components ((:file "package")
;; 'lib' contains general purpose code
(:module "lib"
:serial t
:components ((:file "log")
(:file "list")
(:file "name")
(:file "rpc")
(:file "process")
(:file "message")
(:file "json")
(:file "uri")))
(:file "session")
(:file "protocol")
(:file "server")))

(defsystem #:coalton-lsp/tests
:depends-on (#:coalton-lsp
#:fiasco)
:pathname "tests/"
:serial t
:components ((:file "package")
(:file "mock")
(:file "json-tests")
(:file "lsp-tests")
(:file "message-tests")
(:file "protocol-tests")
(:file "rpc-tests")
(:file "session-tests")))
Loading

0 comments on commit 6841cad

Please sign in to comment.