Code Monkey home page Code Monkey logo

nim.nvim's Introduction

Nim language plugin for NeoVim

This plugin is still pretty much a work-in-progress.

CI

asciicast

Requirements

  • neovim >= 0.4.3
  • nim >= 0.20 (choosenim can be used to install this version)

Installation

Features

  • Semantic highlighting with nimsuggest. Highlight as you type (experimental)
  • "Go to Definition" support using nimsuggest.
  • Autocompletion using nimsuggest.
  • Find references to a symbol.
  • Get signature and documentation of a symbol.
  • Section movements!
  • NEP-1 style indentation!
  • And more...

Auto completion

Install prabirshrestha/asyncomplete.vim and configure it to your liking.

Add this to your configuration file to register the autocomplete source:

au User asyncomplete_setup call asyncomplete#register_source({
    \ 'name': 'nim',
    \ 'whitelist': ['nim'],
    \ 'completor': {opt, ctx -> nim#suggest#sug#GetAllCandidates({start, candidates -> asyncomplete#complete(opt['name'], ctx, start, candidates)})}
    \ })
Support for different completion plugins

While prabirshrestha/asyncomplete.vim is the most tested plugin for use with nim.nvim, it's worth noting that this plugin was made to support a wide range of completion plugins.

If your favorite completion plugin supports asynchronous completion sources in vimscript, the functions in autoload/nim/suggest/sug.vim can be used to integrate nim.nvim with it. Details on how to do so differs between plugins, so please refer to your completion plugin's documentations.

See Support for other completion plugins for pre-made configuration snippets for other plugins.

If you have any questions, you can find me in the #nim IRC channel under the handle leorize.

Usage

See the project's wiki for more information.

nim.nvim's People

Contributors

alaviss avatar amopel avatar belamenso avatar gradha avatar n0bra1n3r avatar uga-rosa avatar zevv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

nim.nvim's Issues

E475: Invalid value for argument cmd: 'nimsuggest' is not executable

Hi,

Thank you for this package.

I am currently using the following nvim version:

NVIM v0.5.0-nightly-6-gef0398f

I am not sure when the plugin started giving me the above error, I suppose it was after a snap update. Could you please help me debug this?

The entire error reads:

Error detected while processing function nim#suggest#ProjectFindOrStart[4]..nim#
suggest#ProjectStart[1]..nim#suggest#ProjectFileStart[7]..nim#suggest#manager#Ne
wInstance:
line    1:
E475: Invalid value for argument cmd: 'nimsuggest' is not executable
Error detected while processing function nim#suggest#ProjectFindOrStart:
line    4:
E171: Missing :endif

stable version of nimsuggest immediately error-exits

Whenever NeoVim loads a .nim file this error message occurs:

nimsuggest instance for project <project path> exited with exitCode: 1

This only happens with the stable version of nimsuggest, with the devel version it all works.

Error editing nvim (Linux/osx)

After installing plugin and setting up nimsuggest, I keep seeing this error on several of my devices.
Every time I try to edit in neovim now.
If you need more information please let me know.

Error detected while processing function nim#suggest#ProjectFindOrSt
art[4]..nim#suggest#ProjectStart[1]..nim#suggest#ProjectFileStart[7]
..nim#suggest#manager#NewInstance:
line 3:
E121: Undefined variable: self
E15: Invalid expression: 'suggest-manager-exec: nimsuggest (' . self
.cmd . ') cannot be executed'
Error detected while processing function nim#suggest#ProjectFindOrSt
art:
line 4:
E171: Missing :endif
Press ENTER or type command to continue

[Question] Preview window

The asciinema shows a preview window appearing as you move about the popup menu. However, I cannot get this to work. Is there a trick to making the preview window appear?

Neovim stuck a 100% CPU

This is a summary of the discussion of PMunch/nimlsp#77.

It seems it is related to this plugin instead.

When opening a Nim file with Neovim, it gets stucks at 100% CPU after the file is opened for a while. Some action (?) will trigger the bug instantly (inserting "{" will do that for instance).

The bug happpend when opening the file https://github.com/SciNim/flambeau/blob/master/flambeau/raw_bindings/tensors.nim
Here is what I do that reproduce :

  • Open tensors.nim
  • Wait around 30 seconds
  • Press "o" (newline + insert mode)
  • Write "{" character

This is on NVIM v0.5.0-dev+1176-g94381310c2. I'll update to the new nightly NVIM v0.5.0-dev+1227-gb518b9076 and test again but I had the same result with v0.4.3 and v0.4.4.

using :set syntax=off or another syntax highlighting plugin solves the issue

Neovim Startup Error

When I open any *.nim file with neovim, I get this error message:

Error detected while processing ~/.local/share/nvim/plugged/nim.nvim/syntax/nim.vim:
line  161:
E15: Invalid expression: . 'start=+\<\%(' .. nim#SearchIdentifierRegex('emit') .. '\|' .. nim#SearchIdentifierRegex('cod
egendecl') .. '\)\m\s*:+ ' .. 'end=+\ze\%(,\|\.\?}\)+ ' .. 'contains=@nimKeywordGroup,@nimLiteralGroup,@nimCommentGroup,
nimPragma,nimEmit.\+ ' .. 'contained'
Press ENTER or type command to continue

It sounds like there are some syntax errors in nim.vim ?

The errors are far from breaking (syntax highlighting still works, etc.) but I thought you should know about this. Cheers for making this awesome plugin!

"go to definition" doesn't work for devel version of Nim installed with choosenim

For a Nim devel version installed with choosenim, the Nim base path is $HOME/.choosenim/toolchains/nim-#devel/. When "go to definition" tries to open a source file under this path, the # in the base path is replaced with the file name of the buffer the command was started from, so the source file with the definition is not found.

Improve gO outline

The current outline is pretty lackluster:
image
As shown in the screenshot, it's not easy to tell overloads apart, and object fields and local variables add a lot of noise and make the outline harder to navigate.

Here are my suggestions on improving it:

  • allow the user to hide certain parts of the outline, eg. fields and local variables, perhaps using a simple config system like let g:nim#outline_hide_fields = 0 or let g:nim#outline_hide = ["fields", "localvars"]
  • show proc/iterator/template/macro signatures and var/let/const/field types

Personalize syntax highlighting color

Hi,

Is there an easy way to personalize which colour are which element (for example I'd like strings to be a different colour than proc, variable to be white by default etc...) or do I have to modify the plugin myself ?

Documentation is lacking

  1. The readme needs to be overhauled, and to provide information at minimum about the default keybindings and the available configuration parameters.
  2. Comprehensive online documentation should be provided in Vim format.

Support for null-ls

I managed to set up nim.nvim as a source for null-ls, which allows it to be used with any completion engine that supports LSP. Here's the code:

local null_ls = require "null-ls"

local CompletionItemKind = vim.lsp.protocol.CompletionItemKind
local kinds = {
  d = CompletionItemKind.Keyword,
  f = CompletionItemKind.Function,
  t = CompletionItemKind.Struct,
  v = CompletionItemKind.Variable,
}

return {
  method = null_ls.methods.COMPLETION,
  filetypes = { "nim" },
  generator = {
    async = true,
    fn = function(params, done)
      vim.fn["nim#suggest#sug#GetAllCandidates"](function(start, candidates)
        local items = vim.tbl_map(function(candidate)
          return {
            kind = kinds[candidate.kind] or CompletionItemKind.Text,
            label = candidate.word,
            documentation = candidate.info,
          }
        end, candidates)
        done { { items = items } }
      end)
    end,
  },
}

Simply put this in a Lua file and then require the file in the list of sources.

Highlighting sometimes disappears

Sometimes, when editing, the dynamic syntax highlighting stops working for a block of code. When this happens, the code only has some barebones highlighting for keywords and literals, and most of it remains gray.

image

Sometimes, the highlighting disappears in the middle of a procedure and not just a block:

image

nimsuggest instance for project ... stopped with exitcode: 1

I have installed this plugin on my Ubuntu 20.04 machine by adding Plug 'alaviss/nim.nvim'
into ./config/nvim/init.vim file, followed by running nvim and :PlugInstall.

The Nim language code becomes now nicely highlighted, but gd, gD do not jump into function definitions.

When I open the file such as nvim gltf.nim inside the cloned repo guzba/gltfviewer, this shows up at the bottom of neovim:
nimsuggest instance for project /home/tokyo/gltfviewer/src stopped with exitcode: 1
and when pressing gd/gD:
nim.nvim: instance is not running

This is a similar issue reported before and closed (#16), yet it occurs with newer nim/nimsuggest versions, i.e.
nimsuggest --version Nim Compiler Version 1.4.0 [Linux: amd64] Compiled at 2020-10-18 Copyright (c) 2006-2020 by Andreas Rumpf

It seems that nimsuggest itself runs fine, i.e. running in the terminal nimsuggest gltf.nim produces the green-colored lines:
nimsuggest gltf.nim Hint: used config file '/home/tokyo/.choosenim/toolchains/nim-1.4.0/config/nim.cfg' [Conf] Hint: used config file '/home/tokyo/.choosenim/toolchains/nim-1.4.0/config/config.nims' [Conf] Hint: used config file '/home/tokyo/gltfviewer/config.nims' [Conf] ...
So nimsuggest is installed and is visible, yet nim.nvim stops it upon loading somehow.

nimsuggest cannot be executed: Vim(let): E475 error

Following up with what I mentioned at #42. This error ocurrs whenever I save the file I am editing.

image

More information on my system:

:echo system(['nimsuggest', '-v'])

Generates

E475: Invalid value for argument cmd: 'nimsuggest' is not executable
NVIM v0.8.2
Build type: RelWithDebInfo
LuaJIT 2.0.5
Compilation: /usr/bin/x86_64-solus-linux-gcc -mtune=generic -march=x86-64 -g2 -O2 -pipe -fPIC -Wformat -Wformat-security -D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=32 -fasynchronous-unwind-tables -ftree-vectorize -feliminate-unused-debug-types -fno-plt -Wall -Wno-error -Wp,-D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/build/YPKG/root/neovim/build/neovim-0.8.2/solusBuildDir/cmake.config -I/home/build/YPKG/root/neovim/build/neovim-0.8.2/src -I/usr/include -I/home/build/YPKG/root/neovim/build/neovim-0.8.2/solusBuildDir/src/nvim/auto -I/home/build/YPKG/root/neovim/build/neovim-0.8.2/solusBuildDir/include
Compiled by build@paddedroom

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info
luis@solus ~ $ nimsuggest -v
Nim Compiler Version 1.6.10 [Linux: amd64]
Compiled at 2022-11-21
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: f1519259f85cbdf2d5ff617c6a5534fcd2ff6942
active boot switches: -d:release -d:danger --gc:markAndSweep

Issue with directory-wide nim config scripts

Hi, I noticed that while a per-module config script is properly used (ex: myscript.nims works for myscript.nim), the dir-wide versions (config.nims or nim.config) are not processed. This causes incorrect error highlighting for a lot of things, including the unit-tests generated by nimble since this plugin is not passing the imports to nim-suggest as far as I can tell. It also results in broken imports not being highlighted as well.

Can't install, Please help

Hi, i tried to type this command "plug 'alaviss/nim.nvim' " and hit enter. But it says that--
"'plug' is not recognized as an internal or external command,
operable program or batch file. "
Please provide detailed information about how to install.

Function signature in preview window

I'm using your plugin and it's very practical !

I'm also using the advised autocomplete plugin and I have the full documentation in the preview window, however I don't have the signature and I don't know what arguments are needed. The autocomplete menu only appears while I'm completing; as soon as there's the opening parenthesis the menu disappears and I don't remember what the signature is.

Is it possible to add this in the preview window ?

Highlighting disappears ยฒ

So I'm trying for days to get my linux config running on windows with nvim-qt.
Not sure if thats actually the same issue like #18 but highlighting dissapears everytime once I start to write anything.
Thats for me reproducible with a clean config just with nim.nvim load and any nim file.

Is there any log/debug I could activate to see what happens?

Video

issue importing the autocompletion code to my init.lua

with my limited knowledge I decide to attempt to import the autocompletion code provided to lua, which didn't seem that hard since I had already setup some autocommand stuff

local cmd = vim.cmd 
cmd("autocmd User asyncomplete_setup call asyncomplete#register_source({
    \ 'name': 'nim',                                    
    \ 'whitelist': ['nim'],
    \ 'completor': {opt, ctx -> nim#suggest#sug#GetAllCandidates({start, candidates -> asyncomplete#complete(opt['name'], ctx, start, candidates)})}
    \ })")

unfortunately this gave me an error when trying to load nvim

Error detected while processing /home/jan-sopi/.config/nvim/init.lua:
E5113: Error while calling lua chunk: vim/_init_packages.lua:0: /home/jan-sopi/.config/nvim/lua/general.lua:18: unfinished string near '"autocmd User asyncomplete_setup call asyncomplete#register_source({'
stack traceback:
        [C]: in function 'error'
        vim/_init_packages.lua: in function <vim/_init_packages.lua:0>
        [C]: in function 'require'
        /home/jan-sopi/.config/nvim/init.lua:1: in main chunk

so yeah, I'm not sure what's wrong since there doesn't appear to be any "unfinished string". did anyone manage to import the script to lua and if so what did I do wrong?

Syntax highlighting in macros

Hi,

I just noticed that syntax highlighting doesn't work quite well in macros, especially when nesting them. Like so:

smth

Should not display exit message unless something went wrong

I'm seeing a message printed to the terminal screen when I exit neovim after editing a nim file. The message says "nimsuggest instance for project [projectName] exited with exitcode: [exitcode]"

It would be better imho to only show the message if nimsuggest exited with with a code besides 0/success.

(eg. in file autoload/nim/suggest.vim, check a:data != 0 in OnEvent function)

Disable error coloring

Hi, I found quite annoying to have the "red" highlight before I finish typing a word: is there a way to disable this kind of error checking?

Thanks a lot for this great plugin!

Pragma name equality

Problem with pragmas injectStmt, codegenDecl, noDecl.
In syntax/nim.vim they are written in lower case, but this is not how they appear in the manual, which causes them not to be highlighted properly.

This hints at a bigger problem: pragmas in Nim are compared using standard name equality. The following code is correct and compiles, but the plugin does not highlight it correctly:

proc a(): int {.discardABLE.} = 7

External Libs (BASS) are highlighted bg-red although it compiles error-free

I am using NVIM for Nim development and have some highlighting issues when using nimble packages.

For some reason NVIM does highlight the BASS and illwill functions with a red error-y background, as you can see here

I am using the alaviss/nim.nvim and asynccomplete.vim plugins alongside treesitter.

How do I get NVIM to actually recognize external functions?

The shown code does compile without issues, so those are not actual errors.

Vim support

Hi Leorize,

Is adding support for Vim technically possible or is there something nvim can do that vim can't?

Customizing Indent Level

Hi. When I turn this plugin on, it overwrites the indent level, which is globally 4 indent level, to 2 indent level.

I am aware that 2 indent level is preferred by the official style guide. However, I do not wish to follow this style guide. Could you tell me how to reset the indent level to be 4?

Releases

Hello and thank you for developing nim.nvim - could you kindly make releases/git tags when useful? Thanks

nimsuggest exits with errorcode 143

  • nvim 0.4.2
  • Windows 10
  • ConEmu, Powershell, GitBash (console doesn't matter; error is the same)
  • nim 1.0.2

When I open a nim file there is no autocomplete or anything.
When I close nvim, I see an error output:

nimsuggest instance for project C:\Users\blablabla stopped with exitcode: 143

Got hightlight but no autocompletion

Here is my nvim version:
image

And here is my ~/.config/nvim/init.vim :
image

Please help~. I usually write code with vscode on a win10, but since I switched to a WSL, I think I can only use a neovim (or a vim) editor. But I can not get it done ๐Ÿ˜ญ

Errors during editing

While editing my code it is often in an "error" state, for example halfway typing an identifier. Would it be possible to defer nimsuggest error checking for a certain idle delay so I do not get flashed at with red letters all of the time?

non-alphabetic operator highlights

For the past year or so I've been using neovim with this plugin, but I patch in these lines:

syntax match   nimOperator        "[-,:{}()\[\]=+*/<>@$~&%|!?^.\\]"

and

highlight default link nimOperator        Operator

I realize that comma(,) colon(:) cannot really be "operators" exactly. I include them since in many fonts, characters like these are harder to distinguish from each other in the same way. Bold facing or bold italic or color shifts can help make them more obvious. There may be better names for the syntax class such as "NonAlphabeticNonQuotingNonUnderscoreASCII" or just "specialChars".. (and the link into Operator could be just up to the user).

I raise this issue just to see if you might be interested in adding a feature like this directly.

Add crash logger for nimsuggest

nimsuggest crashes a lot, and it would be nice if nim.nvim can automatically generate a data dump for reporting issues upstream.

nimsuggest - E730: using List as a String

I just installed your plugin, and when saving a nim file, I get this error message:

nim.nvim: nimsuggest (nimsuggest) cannot be executed: Vim(let):E730: using List as a String

Any ideas?

Error reporting

It would be nice if nim.nvim could accurately report errors in files, on :w. The current best solution seems to be using a separate plug-in (ALE), but due to the fact it uses nim check this simple case fails:

# a.nim
proc thing() =
  echo "hi"
include sub

# sub.nim
thing()  # nim check reports error, but nim c -r a works fine

nim.nvim already leverages nimsuggest and handles the above case correctly, so it should be fairly straightforward to capture any reported errors and underline tokens where these errors appear. Possibly also show them on the commandline.

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.