• Stars
    star
    108
  • Rank 320,132 (Top 7 %)
  • Language
    TypeScript
  • License
    ISC License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Connects language servers with the CodeMirror editor

lsp-editor-adapter (alpha)

A library that automatically presents IDE-like elements for code editors in the browser using the the Language Server Protocol.

Currently, you can connect a CodeMirror document to a language server over WebSockets. Future work will support language servers running in-browser, such as via Service Worker, and also support the Ace editor.

This library is in development. Opening issues and pull requests is greatly appreciated!

Features

The following features are all automatically configured once connected to a language server:

  • Intellisense autocomplete
  • Signature completion
  • Hover tooltips
  • Highlighting matching symbols in document
  • Linting or syntax errors
  • Within the same file: Go to Definition, Type Definition, and Find References

All other features of the language server are not currently supported, but if you would like to add support, please submit a pull request!

Screenshots

These screenshots show the current state of the library:

Javascript/Typescript:

screenshot 2019-01-21 01 03 47

Swift:

screenshot 2019-01-26 17 08 32

screenshot 2019-01-27 13 47 23

screenshot 2019-01-27 13 47 36

screenshot 2019-01-27 13 48 11

Installation

Current requirements:

  • Language server running on a web socket connection, such as jsonrpc-ws-proxy
  • CodeMirror editor with the show-hint addon included
  • Ability to import an ES6 module, which the library is packaged as

Example installation and connection:

import * as CodeMirror from 'codemirror';
// You are required to install the show-hint addon
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/addon/hint/show-hint';

// Each adapter can have its own CSS
import 'lsp-editor-adapter/lib/codemirror-lsp.css';
import { LspWsConnection, CodeMirrorAdapter } from 'lsp-editor-adapter';

let editor = CodeMirror(document.querySelector('.editor'), {
  value: 'hello world',

  // Optional: You can add a gutter for syntax error markers
  gutters: ['CodeMirror-lsp']
});

// Take a look at how the example is configured for ideas
let connectionOptions = {
  // Required: Web socket server for the given language server
  serverUri: 'ws://localhost:8080/html',
  // The following options are how the language server is configured, and are required
  rootUri: 'file:///path/to/a/directory',
  documentUri: 'file:///path/to/a/directory/file.html',
  documentText: () => editor.getValue(),
  languageId: 'html',
};

// The WebSocket is passed in to allow testability
let lspConnection = new LspWsConnection(editor)
  .connect(new WebSocket('ws://localhost:8080'));

// The adapter is what allows the editor to provide UI elements
let adapter = new CodeMirrorAdapter(lspConnection, {
  // UI-related options go here, allowing you to control the automatic features of the LSP, i.e.
  suggestOnTriggerCharacters: false
}, editor);

// You can also provide your own hooks:
lspConnection.on('error', (e) => {
  console.error(e)
});

// You might need to provide your own hooks to handle navigating to another file, for example:
lspConnection.on('goTo', (locations) => {
  // Do something to handle the URI in this object
});

// To clean up the adapter and connection:
adapter.remove();
lspConnection.close();

Running the example

A fully-functional example project which runs three language servers and allows editing all three files is available at /example

To run the example:

cd example
npm install
npm run start

then visit localhost:4000

Developing

To develop against this library, and see updates in the example, run both of these:

# From parent directory
npx webpack --watch
# From example directory
npm run dev

To run library tests, there are two options:

npm test
npm run test-dev

test-dev will watch the source code and rerun tests in the background

More Repositories

1

kinematics

Forward and inverse kinematics simulation in Javascript
JavaScript
34
star
2

jsonrpc-ws-proxy

Create a web socket interface for any number of language servers running in subprocesses
JavaScript
32
star
3

codemirror-lsp-example

CodeMirror connected to remotely-hosted language server over Web Socket
JavaScript
13
star
4

venture-crapital

Play as a venture capitalist investing in tech bubbles before they pop. Made at the Techcrunch Disrupt Hackathon in 24 hours.
JavaScript
6
star
5

votespry

A real-time SMS voting app with zero registration required
JavaScript
3
star
6

MyNEU-ui

A better portal for Northeastern University
JavaScript
3
star
7

sourcekit-lsp-docker

A Dockerfile for running the Sourcekit-LSP project on docker
Dockerfile
2
star
8

hci.wylie.su

A blog about human-computer interaction
Ruby
2
star
9

dom-simulator

Teaching tool that visually represents an HTML document structure and shows you how to change it
JavaScript
2
star
10

mercola

HTML
2
star
11

husky-hours

Collect and distribute the hours of services on campus
JavaScript
1
star
12

blockdude-kinect

BlockDude with a gesture interface
Java
1
star
13

westvillageh.com

So, this is a thing
JavaScript
1
star
14

internlunch

Rails app for showing interns who work near you, with a button to send a Facebook message
Ruby
1
star
15

timeline-trace

Traces a timeline of showing which lines are running and what data they contain
JavaScript
1
star
16

dotfiles

My personal configuration files
Vim Script
1
star
17

hackrtools

Simple Rails app. Save code snippets or articles for future use.
Ruby
1
star
18

interactive.wylie.su

A blog for a course in interactive media made with Jekyll
JavaScript
1
star