Skip to content

Commit

Permalink
Add plugin-nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
tdroxler committed Apr 11, 2024
1 parent 7204407 commit e5b5c47
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 35 deletions.
76 changes: 41 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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=<path-to-your-log-folder>', '<path-to-your-jar>/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.
Expand Down
3 changes: 3 additions & 0 deletions plugin-nvim/README.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions plugin-nvim/ftdetect/ralph.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
au BufNewFile,BufRead *.ral set ft=ralph
1 change: 1 addition & 0 deletions plugin-nvim/ftplugin/ralph.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setlocal commentstring=//%s
1 change: 1 addition & 0 deletions plugin-nvim/indent/ralph.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Indent file
24 changes: 24 additions & 0 deletions plugin-nvim/plugin/ralph.lua
Original file line number Diff line number Diff line change
@@ -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
})

49 changes: 49 additions & 0 deletions plugin-nvim/syntax/ralph.vim
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit e5b5c47

Please sign in to comment.