From e5b5c47c931832c0288f3ad0986c61456f449249 Mon Sep 17 00:00:00 2001 From: Thomas Droxler Date: Thu, 11 Apr 2024 08:03:41 +0200 Subject: [PATCH] Add `plugin-nvim` --- README.md | 76 ++++++++++++++++++---------------- plugin-nvim/README.md | 3 ++ plugin-nvim/ftdetect/ralph.vim | 1 + plugin-nvim/ftplugin/ralph.vim | 1 + plugin-nvim/indent/ralph.vim | 1 + plugin-nvim/plugin/ralph.lua | 24 +++++++++++ plugin-nvim/syntax/ralph.vim | 49 ++++++++++++++++++++++ 7 files changed, 120 insertions(+), 35 deletions(-) create mode 100644 plugin-nvim/README.md create mode 100644 plugin-nvim/ftdetect/ralph.vim create mode 100644 plugin-nvim/ftplugin/ralph.vim create mode 100644 plugin-nvim/indent/ralph.vim create mode 100644 plugin-nvim/plugin/ralph.lua create mode 100644 plugin-nvim/syntax/ralph.vim diff --git a/README.md b/README.md index 1d9809b76..8234bac38 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,42 @@ Language server for Ralph. Currently supports text document level events and diagnostics. +# Installation + +Go to the [latest release](https://github.com/alephium/ralph-lsp/releases/latest) + +There is currently two ways to install the LSP server, as an executable or as a jar file. + +Please note that the server is meant to be run from a client (like an IDE) and not directly. + +1. Executable + + Download `ralph-lsp.zip`, extract it and add `ralph-lsp/bin` to your `PATH` environment variable. + You can run the server with `ralph-lsp` command. + +2. Jar + + Download `ralph-lsp.jar` and run it with `java -jar ralph-lsp.jar` + # Install VSCode plugin Follow these steps: -1. Download: Get the `.vsix` plugin file from the [latest release](https://github.com/alephium/ralph-lsp/releases). +1. Download: Get the `.vsix` plugin file from the [latest release](https://github.com/alephium/ralph-lsp/releases/latest). 2. Install: - Open Visual Studio Code. - Go to Extensions > Views and More Actions > Install from VSIX... - Select the downloaded `.vsix` file and click "Install". +# Install Neovim plugin + +Install [plugin-nvim](/plugin-nvim) with your favorite plugin manager, for example with [vim-plug](https://github.com/junegunn/vim-plug) +```vim + Plug 'alephium/ralph-lsp', {'rtp': 'plugin-nvim'} +``` + +The plugin adds file type detection, syntax highlighting and start the LSP server, make sure you have `ralph-lsp` available in your `PATH` + # Build the JAR ```shell @@ -22,6 +48,20 @@ sbt "compile; lsp-server/assembly" Look in `target` folder: `.../ralph-lsp/lsp-server/target/scala-2.13/ralph-lsp.jar` +# Build the executable + +```shell +sbt universal:packageBin +``` +zip file will be generated in `target/universal/ralph-lsp.zip` + +For local development, you can run +```shell +sbt stage +``` + +This creates the `target/universal/stage/bin/ralph-lsp` executable + # Build the JAR for VSCode ```shell @@ -41,40 +81,6 @@ code . Run the plugin by selecting the menu option `Run -> Run Without Debugging` or `Run -> Start Debugging`. -# Run LSP in neovim - -Install the [ralph.vim](https://github.com/tdroxler/ralph.vim) plugin with your favorite plugin manager, for file type -detection, highlighting, etc. - -## [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) - -Add the following to your lua configuration - -```lua -local function ralph_init() - - local capabilities = vim.lsp.protocol.make_client_capabilities() - - capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = true - - local root_dir = vim.fs.dirname(vim.fs.find({'ralph.json', 'contracts', 'artifacts'}, { upward = true })[1]) - if root_dir == nil then root_dir = vim.fn.getcwd() end - - vim.lsp.start({ - name = 'ralph-lsp', - cmd = {'java', '-jar', '-DRALPH_LSP_LOG_HOME=', '/ralph-lsp.jar'}, - root_dir = root_dir, - capabilities = capabilities - }) - -end - -vim.api.nvim_create_autocmd('FileType', { - pattern = { 'ralph' }, - callback = function() ralph_init() end -}) -``` - # Configuration After your IDE has booted up, create a mandatory config file named `ralph.json` in your project's root directory. diff --git a/plugin-nvim/README.md b/plugin-nvim/README.md new file mode 100644 index 000000000..421df6ea3 --- /dev/null +++ b/plugin-nvim/README.md @@ -0,0 +1,3 @@ +Nvim plugin for [Alephium](https://alephium.org/) smart contract programming language: [Ralph](https://wiki.alephium.org/ralph/getting-started/) + +This plugin use [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) to provide LSP client diff --git a/plugin-nvim/ftdetect/ralph.vim b/plugin-nvim/ftdetect/ralph.vim new file mode 100644 index 000000000..c62362ad5 --- /dev/null +++ b/plugin-nvim/ftdetect/ralph.vim @@ -0,0 +1 @@ +au BufNewFile,BufRead *.ral set ft=ralph diff --git a/plugin-nvim/ftplugin/ralph.vim b/plugin-nvim/ftplugin/ralph.vim new file mode 100644 index 000000000..3143dd193 --- /dev/null +++ b/plugin-nvim/ftplugin/ralph.vim @@ -0,0 +1 @@ +setlocal commentstring=//%s diff --git a/plugin-nvim/indent/ralph.vim b/plugin-nvim/indent/ralph.vim new file mode 100644 index 000000000..0b646310c --- /dev/null +++ b/plugin-nvim/indent/ralph.vim @@ -0,0 +1 @@ +"Indent file diff --git a/plugin-nvim/plugin/ralph.lua b/plugin-nvim/plugin/ralph.lua new file mode 100644 index 000000000..cf04f0d34 --- /dev/null +++ b/plugin-nvim/plugin/ralph.lua @@ -0,0 +1,24 @@ +local function ralph_init() + + local capabilities = vim.lsp.protocol.make_client_capabilities() + + capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = true + + local root_dir = vim.fs.dirname(vim.fs.find({'build.ralph', 'contracts', 'artifacts'}, { upward = true })[1]) + + if root_dir == nil then root_dir = vim.fn.getcwd() end + + vim.lsp.start({ + name = 'ralph-lsp', + cmd = {'ralph-lsp'}, + root_dir = root_dir, + capabilities = capabilities + }) + +end + +vim.api.nvim_create_autocmd('FileType', { + pattern = { 'ralph' }, + callback = function() ralph_init() end +}) + diff --git a/plugin-nvim/syntax/ralph.vim b/plugin-nvim/syntax/ralph.vim new file mode 100644 index 000000000..0117a1109 --- /dev/null +++ b/plugin-nvim/syntax/ralph.vim @@ -0,0 +1,49 @@ +" Vim syntax file +" Language: Ralph + +syn keyword ralphConditional if else +syn keyword ralphRepeat for while + +syn keyword ralphStucture Interface TxScript Contract AssetScript enum event extends skipwhite skipempty nextgroup=ralphInstanceDeclaration +syn keyword ralphKeyword fn nextgroup=ralphFunctionName skipwhite skipempty +syn keyword ralphKeyword pub nextgroup=ralphPubScope skipwhite skipempty +syn keyword ralphKeyword return implements +syn keyword ralphKeyword let mut const nextgroup=ralphNameDefinition skipwhite skipempty +syn keyword ralphStorage Abstract + +syn match ralphInstanceDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained +hi link ralphInstanceDeclaration Special + +syn match ralphNameDefinition /\<[_A-Za-z0-9$]\+\>/ contained +hi link ralphNameDefinition Function + +syn match ralphFunction /[A-Za-z0-9]\+!/ +hi link ralphFunction Function + +syn match ralphFunctionName "\%(r#\)\=\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained + +syn keyword ralphType Bool I256 U256 Address ByteVec +syn keyword ralphBoolean true false + +syn match ralphOperator display "\%(+\|-\|/\|*\|=\|\^\|&\||\|!\|>\|<\|%\)=\?" + +syn match ralphArrowCharacter display "->" + +syn region ralphCommentLine start="//" end="$" + +hi def link ralphNumber Number +hi def link ralphBoolean Boolean +hi def link ralphEnum ralphType +hi def link ralphEnumVariant ralphConstant +hi def link ralphConstant Constant +hi def link ralphOperator Operator +hi def link ralphStucture Structure +hi def link ralphKeyword Keyword +hi def link ralphRepeat Conditional +hi def link ralphConditional Conditional +hi def link ralphFunctionName Function +hi def link ralphCommentLine Comment +hi def link ralphType Type +hi def link ralphStorage StorageClass + +let b:current_syntax = "ralph"