Giter Club home page Giter Club logo

vim9-syntax's Introduction

Syntax plugin for Vim9. Work in progress.

Configuration

The highlighting can be controlled via keys in the dictionary g:vim9_syntax:

  • builtin_functions controls whether builtin functions are highlighted (true by default)
  • data_types controls whether Vim9 data types in declarations are highlighted (true by default)
  • user_types controls whether user types are highlighted (:help :type; false by default)
  • errors controls whether some possible mistakes are highlighted
  • fenced_languages is a list of languages which should be highlighted with their own syntax when included inside fenced codeblocks (empty list by default)

g:vim9_syntax.errors is a nested dictionary containing these keys:

  • event_wrong_case controls whether names of events in autocmds are highlighted as errors, if they don't have the same case as in the help (false by default)
  • octal_missing_o_prefix controls whether an octal number prefixed with 0 instead of 0o is highlighted as an error (false by default)
  • range_missing_space controls whether no space between a line specifier and a command is highlighted as an error (false by default)
  • range_missing_specifier controls whether an implicit line specifier is highlighted as an error (false by default)
  • strict_whitespace controls whether missing/superfluous whitespace is highlighted as an error (true by default)

Example of configuration:

g:vim9_syntax = {
   builtin_functions: true,
   data_types: false,
   user_types: false,
   fenced_languages: ['lua', 'python'],
   errors: {
       event_wrong_case: false,
       octal_missing_o_prefix: false,
       range_missing_space: false,
       range_missing_specifier: false,
       strict_whitespace: true,
   }
}

Requirements

A recent Vim version.

Installation

Linux

Run this shell command:

git clone https://github.com/lacygoill/vim9-syntax.git ~/.vim/pack/vim9-syntax/opt/vim9-syntax

Then, add this line in your vimrc:

packadd! vim9-syntax

Windows

Run this shell command:

git clone https://github.com/lacygoill/vim9-syntax.git %USERPROFILE%\vimfiles\pack\vim9-syntax\opt\vim9-syntax

Then, add this line in your vimrc:

packadd! vim9-syntax

vim9-syntax's People

Contributors

lacygoill avatar monkoose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vim9-syntax's Issues

Some valid :profile sub commands show error

profile stop and profile dump show the sub command stop and dump as an error. I took a look at the source, but I've never worked with syntax-hl and quickly stopped looking.

includes

@  changeset:   174:46ddce48cfe9
|  bookmark:    main
|  tag:         default/main
|  tag:         tip
|  user:        lagygoill <[email protected]>
|  date:        Sun May 22 21:03:29 2022 +0200
|  summary:     support bitwise shift operators

@lacygoill (since I don't know if you monitor these issues)

Syntax is broken when CompilerSet contains line continuations

errorformat can be quite long. So I often split it across multiple lines. I've noticed that this isn't supported yet.

Example:

vim9script

CompilerSet errorformat=
        \%D%*\\a[%*\\d]:\ Entering\ directory\ %*[`']%f',
        \%X%*\\a[%*\\d]:\ Leaving\ directory\ %*[`']%f',
        \%D%*\\a:\ Entering\ directory\ %*[`']%f',
        \%X%*\\a:\ Leaving\ directory\ %*[`']%f'

screenshot-2022-10-03_002039

Sometimes RHS of mapping is highlighted as vim9MarkCmdArgInvalid

I have quite a few motion mappings similar to the following:

vim9script
# Jump to next/previous git conflict marker
nnoremap ]x <scriptcmd>mark `<bar>range(v:count1)->map((_, _) => search('^\(<\\|=\\|>\)\{7}\([^=].\+\)\?$', 'W'))<cr>
nnoremap [x <scriptcmd>mark `<bar>range(v:count1)->map((_, _) => search('^\(<\\|=\\|>\)\{7}\([^=].\+\)\?$', 'bW'))<cr>
xnoremap ]x <scriptcmd>mark `<bar>range(v:count1)->map((_, _) => search('^\(<\\|=\\|>\)\{7}\([^=].\+\)\?$', 'W'))<cr>
xnoremap [x <scriptcmd>mark `<bar>range(v:count1)->map((_, _) => search('^\(<\\|=\\|>\)\{7}\([^=].\+\)\?$', 'bW'))<cr>

Unfortunately, after the mark the syntax file highlights some parts of the RHS as vim9MarkCmdArgInvalid.

Screenshot:
screenshot-2022-09-29_005244

Adding a ` to mark_valid fixes the issue, but only if we also add a whitespace before the <bar>:

diff --git a/import/vim9Language.vim b/import/vim9Language.vim
index 7f5e6aa..cd0d56b 100644
--- a/import/vim9Language.vim
+++ b/import/vim9Language.vim
@@ -1472,7 +1472,7 @@ export const logical_not: string = '/\w\@1<!![~=]\@!!*/'

 # mark_valid {{{1

-export const mark_valid: string = '[a-zA-Z''[\]<>0-9"^.(){}]'
+export const mark_valid: string = '[a-zA-Z`''[\]<>0-9"^.(){}]'

 # maybe_dict_literal_key {{{1

screenshot-2022-09-29_005226

An improvement would be to add <bar> to the regex in the syntax match vim9MarkCmdArg, but I don't know if you want to further complicate the regex:

diff --git a/syntax/vim.vim b/syntax/vim.vim
index f0288c8..1ef0ca0 100644
--- a/syntax/vim.vim
+++ b/syntax/vim.vim
@@ -1511,7 +1511,7 @@ syntax keyword vim9MarkCmd ma[rk]
     \ skipwhite

 syntax match vim9MarkCmdArgInvalid /[^ \t|]\+/ contained
-execute 'syntax match vim9MarkCmdArg /\s\@1<=' .. lang.mark_valid .. '\_s\@=/ contained'
+execute 'syntax match vim9MarkCmdArg /\s\@1<=' .. lang.mark_valid .. '\%(\_s\|<bar>\)\@=/ contained'

 # :nnoremap {{{3

screenshot-2022-09-29_005849

Some command-completion attributes are highlighted as `Vim9UserCmdAttrErrorValue`

Some of the command-completion attributes are highlighted as a syntax error. Example:

vim9script

command -nargs=+ -complete=filetype      Test1 echo <q-args>
command -nargs=+ -complete=file          Test2 echo <q-args>
command -nargs=+ -complete=file_in_path  Test3 echo <q-args>
command -nargs=+ -complete=tag           Test4 echo <q-args>
command -nargs=+ -complete=tag_listfiles Test5 echo <q-args>

Screenshot:
screenshot-2022-09-29_012157

This is because the longer attributes are short-circuited in the regex they are defined in. The order matters. Longer names should be defined first.

The following patch fixes the issue:

diff --git a/import/vim9Language.vim b/import/vim9Language.vim
index 7f5e6aa..fabd880 100644
--- a/import/vim9Language.vim
+++ b/import/vim9Language.vim
@@ -628,9 +628,9 @@ const command_complete_type_list: list<string> =<< trim END
     environment
     event
     expression
-    file
-    file_in_path
     filetype
+    file_in_path
+    file
     function
     help
     highlight
@@ -647,8 +647,8 @@ const command_complete_type_list: list<string> =<< trim END
     sign
     syntax
     syntime
-    tag
     tag_listfiles
+    tag
     user
     var
 END

Result:
screenshot-2022-09-29_012202

Can't find this wonderful work in the release?

I looked at a build based on today's release and don't see vim9-syntax in there. I looked prompted by #13047 (which you commented on).

Is there a reason this isn't available. I'd be very unhappy if I wasn't using it.

Thanks

I'd like to try this, stumbled across this and I've been unhappy with vim9 syntax highlighting...

Had to look up vim stuff to install, seems to be working. Thanks. the lambdas were the worst, they look good now.

The README for tools is out of date, and I figure I don't need to run the Generator script.

Many thanks.

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.