Giter Club home page Giter Club logo

tremor-language-server's Introduction

Tremor Language Server (Trill)

WIP server for use with editors and IDEs, when working with tremor's languages. Follows language server protocol.

Features

Diagnostics

tremor-script interpreter errors (as you type or on file save), with hints for fixing (as applicable)

nice-to-have: apply fix suggestions from errors

Completion

code completion (as you type/on-demand) for module functions -- function names with signature/doc info as well as placeholders for arguments.

nice-to-have: code completion for variables as well as other language constructs

Hover

diagnostics and function documentation on mouse hover (or editor command)

nice-to-have: documentation for variables (eg: assignment info)

Navigation

nice-to-have: find all references, symbol search

for later: Go to definiton, peek definition, symbol list (when tremor script has functions)

Refactoring

nice-to-have: rename all references

Quickstart

For installation:

RUSTFLAGS='-C target-cpu=native' cargo install tremor-language-server

Make sure .cargo/bin is in your $PATH (or install it somewhere in your $PATH via cargo).

If you are developing on the language server:

git clone [email protected]:tremor-rs/tremor-language-server.git
cd tremor-language-server

# build and link somewhere in your path (for easy access/use in testing via editors)
cargo build
ln -s target/debug/tremor-language-server ~/bin/ # or anywhere in your $PATH

# to install the release build
cargo install --path . --root ~/ # make sure ~/bin/ is in your $PATH

VS Code setup

Follow instructions at:

https://github.com/tremor-rs/tremor-vscode

Vim setup

Prerequisite: install https://github.com/tremor-rs/tremor-vim so that vim is aware of tremor filetypes (you also get syntax highlighting as a bonus).

ale

For use with vim, we have a forked version of ale that can interact with the tremor language server:

https://github.com/anupdhml/ale/tree/tremor

Follow the plugin installation instructions. If you are using vim-plug, this will do:

Plug 'anupdhml/ale', { 'branch': 'tremor' }

Vim and ale settings that work nice with the tremor language server:

" completion menu
set completeopt=menuone,longest,popup " always show the menu, insert longest match, use popup window for extra info
"set completepopup=border:off          " remove the border from the completion popup window

" turn on omnicomplete based on ale
set omnifunc=ale#completion#OmniFunc

" enable ale completion (as you type), where available
"let g:ale_completion_enabled = 1

" turn on vim mouse support in all modes (for hover info)
set mouse=a

" show hover information on mouse over (vim mouse support should be turned on)
" xterm2 makes hover work with tmux as well
let g:ale_set_balloons = 1
set ttymouse=xterm2

" only run linters named in ale_linters settings
let g:ale_linters_explicit = 1

" active linters
let g:ale_linters = {
\   'tremor': ['tremor-language-server'],
\   'trickle': ['tremor-language-server'],
\}

" when to run linting/fixing. choose as desired
"
" aggressive
let g:ale_fix_on_save = 1
let g:ale_lint_on_text_changed = 'always'
let g:ale_lint_on_enter = 1
let g:ale_lint_on_insert_leave = 1
"
" conservative
"let g:ale_lint_on_text_changed = 'never'
"let g:ale_lint_on_enter = 0
"let g:ale_lint_on_insert_leave = 0

" key mappings
nmap <silent> <leader>j <Plug>(ale_next_wrap)
nmap <silent> <leader>k <Plug>(ale_previous_wrap)
nmap <silent> <leader>/ <Plug>(ale_hover)
nmap <silent> <leader>? <Plug>(ale_detail)
nmap <silent> <leader>] <Plug>(ale_go_to_definition)
nmap <silent> <leader># <Plug>(ale_find_references)

You might want to show ALE counters in your vim status line. If you are using vim lightline:

" for showing linter errrors/warnings. depends on lightline-ale
let g:lightline.component_expand = {
    \  'linter_checking': 'lightline#ale#checking',
    \  'linter_warnings': 'lightline#ale#warnings',
    \  'linter_errors': 'lightline#ale#errors',
    \  'linter_ok': 'lightline#ale#ok',
    \ }
let g:lightline.component_type = {
    \  'linter_checking': 'left',
    \  'linter_warnings': 'warning',
    \  'linter_errors': 'error',
    \  'linter_ok': 'left',
    \ }
let g:lightline#ale#indicator_checking = ''
let g:lightline#ale#indicator_warnings = ''
let g:lightline#ale#indicator_errors = ''
let g:lightline#ale#indicator_ok = ''

" configure lightline components
let g:lightline.active = {
    \   'left':  [ ['mode', 'paste'],
    \              ['fugitive', 'readonly', 'filename', 'modified'] ],
    \   'right': [ [ 'lineinfo' ],
    \              [ 'percent' ],
    \              [ 'fileformat', 'fileencoding', 'filetype' ],
    \              ['linter_checking', 'linter_errors', 'linter_warnings', 'linter_ok' ] ]
    \ }

" ale indicators (aligned with indicators used in lightline-ale)
" 2 chars to cover the full sign width
let g:ale_sign_warning = '▲▲'
let g:ale_sign_error = '✗✗'

For more ale setup and vim configuration:

https://github.com/anupdhml/dotfiles/blob/virtualbox_new/data/.vimrc

coc-nvim

Install coc.nvim as described in their README.

Start vim and enter :CocConfig and enter the following as additional entry:

{
  "tremor": {
    "command": "tremor-language-server",
    "fileTypes": ["tremor", "trickle"]
  }
}

Other VIM language server clients

If you prefer not to use ale or coc-nvim, these vim plugins should also work well as the server client:

Notes

  • If you are using vim from terminal and not seeing error diagnostics or function docs on hover, check if the vim version you are using has been compiled with balloon support -- output of vim --version should show items +balloon_eval and +balloon_eval_term. If not, you will need to find a vim package for your environment with the support baked in (or compile vim yourself). Eg: for mac, this may mean installing macvim via homebrew.
  • By default, vim's omni-completion items (eg: tremor function names after typing module_name::) are triggered via Ctrl-x Ctrl-o, while normal keyword completion is via Ctrl-p/Ctrl-n. If you prefer a more accessible keybinding for these (eg: Tab), have a look at extensions like VimCompletesMe, or Supertab.

TODO

  • integration for emacs
  • support parallel edits for trickle and tremor files
  • improve debugging
  • add tests
  • ability to handle multiple script errors
  • use simd-json in tower and json rpc crates?
  • distribution without compiling

tremor-language-server's People

Contributors

anupdhml avatar darach avatar dependabot-preview[bot] avatar dependabot[bot] avatar ebkalderon avatar licenser avatar mfelsche avatar primalpimmy avatar web-flow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tremor-language-server's Issues

RUSTSEC-2020-0159: Potential segfault in `localtime_r` invocations

Potential segfault in localtime_r invocations

Details
Package chrono
Version 0.4.19
URL chronotope/chrono#499
Date 2020-11-10

Impact

Unix-like operating systems may segfault due to dereferencing a dangling pointer in specific circumstances. This requires an environment variable to be set in a different thread than the affected functions. This may occur without the user's knowledge, notably in a third-party library.

Workarounds

No workarounds are known.

References

See advisory page for additional details.

Doesn't compile

Version from cates.io doesnt compile with this error:

 Compiling lalrpop v0.18.1
error[E0308]: mismatched types
   --> /home/username/.cargo/registry/src/github.com-1ecc6299db9ec823/simd-json-0.3.3/src/lib.rs:213:86
    |
213 | fn please_compile_with_a_simd_compatible_cpu_setting_read_the_simdjonsrs_readme() -> ! {}
    |    ----------------------------------------------------------------------------      ^ expected `!`, found `()`
    |    |
    |    implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected type `!`
            found unit type `()`

In git version there is lalrpop v0.17.2 and everything works.

Show function params and return types in completion items for tremor-script

In the overall list of possible function completions for tremor-script, param and return type is not included currently. It used to work pre 0.8 (since we used to parse the doc markdown files where that info was structured in a certain way).

Once there’s support for encoding this info in a structured manner as part of tremor function doc, we can modify the language server to use it.

Panic due to invalid index

During development, while editing some trickle code, in a state where stuff doesnt compile i get multiple panics from the language server v0.10.0 like this:

thread 'main' panicked at 'index out of bounds: the len is 2 but the index is 18446744073709551615', src/lsp_utils.rs:59:55
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

RUSTSEC-2021-0124: Data race when sending and receiving after closing a `oneshot` channel

Data race when sending and receiving after closing a oneshot channel

Details
Package tokio
Version 0.2.25
URL tokio-rs/tokio#4225
Date 2021-11-16
Patched versions >=1.8.4, <1.9.0,>=1.13.1
Unaffected versions <0.1.14

If a tokio::sync::oneshot channel is closed (via the
oneshot::Receiver::close method), a data race may occur if the
oneshot::Sender::send method is called while the corresponding
oneshot::Receiver is awaited or calling try_recv.

When these methods are called concurrently on a closed channel, the two halves
of the channel can concurrently access a shared memory location, resulting in a
data race. This has been observed to cause memory corruption.

Note that the race only occurs when both halves of the channel are used
after the Receiver half has called close. Code where close is not used, or where the
Receiver is not awaited and try_recv is not called after calling close,
is not affected.

See tokio#4225 for more details.

See advisory page for additional details.

RUSTSEC-2021-0139: ansi_term is Unmaintained

ansi_term is Unmaintained

Details
Status unmaintained
Package ansi_term
Version 0.12.1
URL ogham/rust-ansi-term#72
Date 2021-08-18

The maintainer has adviced this crate is deprecated and will not
receive any maintenance.

The crate does not seem to have much dependencies and may or may not be ok to use as-is.

Last release seems to have been three years ago.

Possible Alternative(s)

The below list has not been vetted in any way and may or may not contain alternatives;

See advisory page for additional details.

RUSTSEC-2020-0122: beef::Cow lacks a Sync bound on its Send trait allowing for data races

beef::Cow lacks a Sync bound on its Send trait allowing for data races

Details
Package beef
Version 0.4.4
URL maciejhirsz/beef#37
Date 2020-10-28
Patched versions >=0.5.0

Affected versions of this crate did not have a T: Sync bound in the Send impl for Cow&lt;&#39;_, T, U&gt;. This allows users to create data races by making Cow contain types that are (Send && !Sync) like Cell&lt;_&gt; or RefCell&lt;_&gt;.

Such data races can lead to memory corruption.

The flaw was corrected in commit d1c7658 by adding trait bounds T: Sync and T::Owned: Send to the Send impl for Cow&lt;&#39;_, T, U&gt;.

See advisory page for additional details.

RUSTSEC-2020-0071: Potential segfault in the time crate

Potential segfault in the time crate

Details
Package time
Version 0.1.43
URL time-rs/time#293
Date 2020-11-18
Patched versions >=0.2.23
Unaffected versions =0.2.0,=0.2.1,=0.2.2,=0.2.3,=0.2.4,=0.2.5,=0.2.6

Impact

Unix-like operating systems may segfault due to dereferencing a dangling pointer in specific circumstances. This requires an environment variable to be set in a different thread than the affected functions. This may occur without the user's knowledge, notably in a third-party library.

The affected functions from time 0.2.7 through 0.2.22 are:

  • time::UtcOffset::local_offset_at
  • time::UtcOffset::try_local_offset_at
  • time::UtcOffset::current_local_offset
  • time::UtcOffset::try_current_local_offset
  • time::OffsetDateTime::now_local
  • time::OffsetDateTime::try_now_local

The affected functions in time 0.1 (all versions) are:

  • at
  • at_utc

Non-Unix targets (including Windows and wasm) are unaffected.

Patches

Pending a proper fix, the internal method that determines the local offset has been modified to always return None on the affected operating systems. This has the effect of returning an Err on the try_* methods and UTC on the non-try_* methods.

Users and library authors with time in their dependency tree should perform cargo update, which will pull in the updated, unaffected code.

Users of time 0.1 do not have a patch and should upgrade to an unaffected version: time 0.2.23 or greater or the 0.3. series.

Workarounds

No workarounds are known.

References

time-rs/time#293

See advisory page for additional details.

Panic on windows environments during server startup

Seeing following panic during tremor-language-server startup on windows:

C:\Users\juju\TREMOR>set RUST_BACKTRACE=full

C:\Users\juju\TREMOR>tremor-language-server --version
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 3, kind: NotFound, message: "The system cannot find the path specified." }', src\libcore\result.rs:1188:5
stack backtrace:
   0:     0x7ff603958a19 - onig_get_regex_by_callout_args
   1:     0x7ff603970cdb - onig_get_regex_by_callout_args
   2:     0x7ff603955294 - onig_get_regex_by_callout_args
   3:     0x7ff60395b4f9 - onig_get_regex_by_callout_args
   4:     0x7ff60395b14c - onig_get_regex_by_callout_args
   5:     0x7ff60395bd2c - onig_get_regex_by_callout_args
   6:     0x7ff60395b8b0 - onig_get_regex_by_callout_args
   7:     0x7ff60396d20d - onig_get_regex_by_callout_args
   8:     0x7ff60396d30f - onig_get_regex_by_callout_args
   9:     0x7ff6034fbc21 - <unknown>
  10:     0x7ff603537529 - <unknown>
  11:     0x7ff60349ba91 - <unknown>
  12:     0x7ff603513bc9 - <unknown>
  13:     0x7ff6034b8a20 - <unknown>
  14:     0x7ff60350d346 - <unknown>
  15:     0x7ff60395b707 - onig_get_regex_by_callout_args
  16:     0x7ff60395fd72 - onig_get_regex_by_callout_args
  17:     0x7ff60395bf52 - onig_get_regex_by_callout_args
  18:     0x7ff6034b8bd7 - <unknown>
  19:     0x7ff6039a47b4 - onig_unicode_define_user_property
  20:     0x7fff856b7bd4 - BaseThreadInitThunk
  21:     0x7fff85f6ce51 - RtlUserThreadStart

Tested with v0.7.4 of the server (via cargo install tremor-language-server), on rustc 1.41.1 (f3e1a954d 2020-02-24), windows 10.

The server does not error out on linux and mac environments. Fixing this will enable editors like vscode to use the server on windows too.

RUSTSEC-2021-0080: Links in archive can create arbitrary directories

Links in archive can create arbitrary directories

Details
Package tar
Version 0.4.35
URL alexcrichton/tar-rs#238
Date 2021-07-19

When unpacking a tarball that contains a symlink the tar crate may create
directories outside of the directory it's supposed to unpack into.

The function errors when it's trying to create a file, but the folders are
already created at this point.

use std::{io, io::Result};
use tar::{Archive, Builder, EntryType, Header};

fn main() -&gt; Result&lt;()&gt; {
    let mut buf = Vec::new();

    {
        let mut builder = Builder::new(&amp;mut buf);

        // symlink: parent -&gt; ..
        let mut header = Header::new_gnu();
        header.set_path(&quot;symlink&quot;)?;
        header.set_link_name(&quot;..&quot;)?;
        header.set_entry_type(EntryType::Symlink);
        header.set_size(0);
        header.set_cksum();
        builder.append(&amp;header, io::empty())?;

        // file: symlink/exploit/foo/bar
        let mut header = Header::new_gnu();
        header.set_path(&quot;symlink/exploit/foo/bar&quot;)?;
        header.set_size(0);
        header.set_cksum();
        builder.append(&amp;header, io::empty())?;

        builder.finish()?;
    };

    Archive::new(&amp;*buf).unpack(&quot;demo&quot;)
}

This issue was discovered and reported by Martin Michaelis (@mgjm).

See advisory page for additional details.

Update to latest tower-lsp

Author of tower-lsp here! I just wanted to let you know that tower-lsp has been rapidly improving over the past several months and has seen a great many improvements since 0.4.1. Among other things, it has gained:

  • Support for std::future::Future, the newest tokio, and async/await.
  • Support for a crap-ton more LSP requests, almost supporting all of LSP 3.15.
  • Support for all server-to-client requests, renaming Printer to Client.
  • LanguageServer trait methods are no longer required, except for initialize and shutdown.
  • Notification trait methods are now async fn.
  • You can now call .await on serve() directly, eliminating the need for ExitReceiver.
  • Backpressure is now handled properly.

If you would like to port your server to async/await and add some new features to your language server, such as goto declaration, goto definition, goto type definition, code formatting, document symbols, references, etc. 0.9.0 has just been published to Crates.io.

Not exactly sure if this announcement requires an official library RFC as per the contributing guidelines, but if it does, I do sincerely apologize for submitting this suggestion out of form. Feel free to close this issue if that is the case!

Failed to install tremor language server

Error message:

Compiling tremor-language-server v0.10.1
error: failed to run custom build command for `tremor-language-server v0.10.1`

Caused by:
  process didn't exit successfully: `/var/folders/84/zhf78lt50hsghfh5s6g9jmk00000gn/T/cargo-installweU1XI/release/build/tremor-language-server-cf2b09233f27bfff/build-script-build` (exit code: 101)
  --- stdout
  Dumping function docs for tremor-script to: /var/folders/84/zhf78lt50hsghfh5s6g9jmk00000gn/T/cargo-installweU1XI/release/build/tremor-language-server-11042796ebe3999c/out/function_docs.tremor-script.bin
  Detected tremor-script version from cargo lock file: 0.10.1
  Could not find tremor-script src in local cargo registry, so downloading it now...
  Downloading crate `tremor-script==0.10.1` from https://crates.io/api/v1/crates/tremor-script/0.10.1/download

  --- stderr
  thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /Users/rohitdandamudi/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/runtime/blocking/pool.rs:85:33
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `tremor-language-server v0.10.1`, intermediate artifacts can be found at `/var/folders/84/zhf78lt50hsghfh5s6g9jmk00000gn/T/cargo-installweU1XI`

Caused by:
  build failed

OS: MacOS Mojave
Command: tremor-runtime rohitdandamudi$ cargo install tremor-language-server

Language Server Highlighting

This is more a tracking ticket - there is a RFC to integrate highlighting into the language server protocol - if this RFC is accepted we could re-use the highlighting we have in tremor-script instead of having to re-implement it in every editor. That would be a huge win I think.

So I'll drop a link to the upstream Issue on it here: microsoft/language-server-protocol#513

Produce rpm's and deb's with a language server release

We do not currently build language server images ( docker, rpm, deb ) as part of the
release process for tremor. Adding these would mean folk have multiple options to
install the language server without having to install the rust toolchain and doing a build.

The images would be super useful in online IDE's such as github codespaces and gitpod.

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.