Code Monkey home page Code Monkey logo

janet-lsp's Introduction

Janet LSP

A Language Server (LSP) for the Janet programming language.

Overview

The goal of this project is to provide an augmented editor/tooling experience for Janet, via a self-contained, Language Server Protocol-compliant language server (which is itself implemented in Janet!).

Current features include:

  • Auto-completion based on symbols in the Janet Standard Library and defined in user code
  • On-hover definition of symbols as returned by (doc ,symbol)
  • Inline compiler errors
  • Pop-up signature help

Planned features include:

  • Jump to definition/implementation
  • Find references from definition/implementation
  • Refactoring helps
  • Symbol renaming helps

Possible (but de-prioritized) features include:

  • Syntax highlighting for Janet via semantic tokens

Desirable, but possibly more complicated/difficult features include:

  • Stand-alone (i.e. non-Editor-dependent) usage via API/CLI

Caveats

  • MacOS support is mostly untested (but as far as I know there shouldn't be major differences).
  • The only editor integration currently tested against is Visual Studio Code.
  • I've never written a language server before, so I don't really know what I'm doing. Help me, if you'd like!

Clients (i.e. Editors)

Currently, the only editor tested and known working with Janet LSP is Visual Studio Code, which you can try/take advantage of by installing the Janet++ extension from the VS Code marketplace.

Other editors that implement LSP client protocols, either built-in or through editor extensions, include:

  • Emacs
  • vim/neovim
  • Sublime Text
  • Helix
  • Kakoune

If you get Janet LSP working with any of these options, please let me know!

Getting Started (for Development)

Clone this project and Build the stand-alone binary and .jimage file

Requires Janet and jpm.

$ git clone https://github.com/CFiggers/janet-lsp
$ cd janet-lsp
$ jpm deps
$ jpm build

Both a stand-alone (albeit dynamically linked) binary executable and a .jimage (Janet image) file will be generated.

Installing

After running the commands above, the following command will copy the janet-lsp binary to a location that can be executed via the command line.

$ jpm install

Debug Console

Starting in version 0.0.3, you can start a debug console by passing --console to any invocation of Janet LSP, including any of the following:

$ ./build/janet-lsp --console
  OR
$ janet ./build/janet-lsp.jimage --console
  OR
$ janet ./src/main.janet --console

In this mode, the LSP will launch a simple RPC server that listens on port 8037 (by default, configurable with the --debug-port flag). Janet LSPs with version >= 0.0.3 will check for a listening server on port 8037 (or the port specified by --debug-port) and, if found, transmit anything sent through the (logging/log) function to be printed out by the debug console.

In the future, the debug console may function as a networked REPL allowing commands to be sent to the running language server process (but right now it functions in listen-only mode).

Contributions

Issues and Pull Requests welcome.

Prior Art

This project is a hard fork from (with much appreciation to) JohnDoneth/janet-language-server, which is Copyright (c) 2022 JohnDoneth and contributors.

janet-lsp's People

Contributors

cfiggers avatar fnurk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

janet-lsp's Issues

Buggy behavior when `jpm_tree` exists

Currently two (at least) issues are appearing when there is a jpm_tree containing local files:

  1. Some on-hover documentation points toward the jpm_tree, especially module imports (even when the module is not being imported from jpm_tree)
  2. When (import)ing, any symbol inserted will be accepted as valid, even when that module does not exist; any modules contained in jpm_tree will then be suggested by autocompletion namespaced under that symbol
    • (This seems to be happening on each keystroke, meaning that if (import random) is typed, r, ra, ran, rand, etc. are all evaluated)

Probably has something to do with the way modules are being identified in jpm_tree---more experimentation needed.

Problem communicating with helix

I thought I'd try hooking up janet-lsp to a helix modified to work with Janet.

I'm not confident that the modifications were appropriate, but supposing they were for the moment...

Upon opening a .janet file in a custom-built hx, I quickly see the message:

Language server exited

near the bottom of the editor.

Apparently :log-open can show a log for helix and doing that revealed:

2023-10-11T21:18:26.183 helix_lsp::transport [ERROR] janet-lsp err <- "error: bad slot #1, expected string, symbol, keyword or buffer, got <tuple 0x556D94197080>\n"
2023-10-11T21:18:26.183 helix_lsp::transport [ERROR] janet-lsp err <- "  in peg/match [src/core/peg.c] on line 1701\n"
2023-10-11T21:18:26.183 helix_lsp::transport [ERROR] janet-lsp err <- "  in posix/dirname [/home/user/.local/lib/janet/spork/path.janet] on line 150, column 1\n"
2023-10-11T21:18:26.183 helix_lsp::transport [ERROR] janet-lsp err <- "  in find-unique-paths [src/main.janet] on line 186, column 20\n"
2023-10-11T21:18:26.183 helix_lsp::transport [ERROR] janet-lsp err <- "  in main [src/main.janet] on line 205, column 14\n"
2023-10-11T21:18:26.185 helix_lsp [ERROR] failed to initialize language server: server closed the stream
2023-10-11T21:18:26.185 helix_lsp::transport [ERROR] janet-lsp err: <- StreamClosed

I think I'll try to modify janet-lsp to try to ascertain some of the values that are flowing along.

Allow use of custom JANET_PATH/JANET_TREE etc.

I have a setup where my Janet deps live in a user-local folder, allowing the user to specify things like the $JANET_LIBPATH, $JANET_PATH, $JANET_PROFILE, $JANET_HEADERPATH etc. would allow users to use their custom environments.

Make Janet LSP evaluation error tolerant

As currently written, Janet LSP is not error tolerant—that is, the first error encountered is returned and the rest of the file is not evaluated. A better architecture would allow for multiple errors to be encountered and reported.

In some cases, errors are related to one another, such as an issue with importing a module preventing functions that use that module's symbols to evaluate either).

In other cases, such as ambiguous or undefined references, arity mismatches, or other compiler errors, the errors are completely independent.

Janet LSP should be able to report multiple errors, especially ones that are unrelated to one another.

Implement Signature Help

Janet LSP should be able to respond to Signature Help Requests from LSP clients.

This would involve, at minimum:

  • Adding a :signatureHelpProvider key to the :capabilities map in src/main.janet
  • Adding a "textDocument/signatureHelp" case to handle-message in src/main.janet
  • Adding a on-signature-help top level function in src/main.janet
  • Implementing signature help logic (possibly in a new .janet file in the src directory)

Better Sandboxing of User Code

Presently, Janet LSP flychecks the user's code as received from the LSP client in the same environment that the server itself is running in. This creates opportunities for symbol collision and other glitchy behavior.

A better architecture would have user code evaluated in a separate environment table—either by specially-constructing an environment table in eval.janet to be passed to eval-buffer and its run-context call, or by running the functions in eval.janet in a totally separate fiber from the server process itself.

More testing and experimentation needed here.

Module imports not working on Windows

At the moment, a module import such as (import spork/json) causes an error on Windows. This seems to happen with all module imports that are not project local.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.