vlang / vls

V language server. (Old V language server - see v-analyzer)
MIT License
314 stars 53 forks source link

Tree-sitter is giving wrong AST after file changed. #409

Closed SirZenith closed 1 year ago

SirZenith commented 1 year ago

System Information

V doctor

OS: windows, Microsoft Windows 11 רҵ�� v22621 64-bit
Processor: 16 cpus, 64bit, little endian, Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz  
CC version: cc (Rev6, Built by MSYS2 project) 12.2.0

getwd: C:\Users\PC\.vls\reports
vmodules: C:\Users\PC\.vmodules
vroot: F:\Programming\V\v
vexe: F:\Programming\V\v\v.exe
vexe mtime: 2022-12-22 08:16:00
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.2 3c5cfa2

Git version: git version 2.39.0.windows.2
Git vroot status: weekly.2022.50-55-g3c5cfa22 (26 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-windows-amd64 cb89a4fe

VLS info

vls version 0.0.1.f0aa56e

Problem Description

During file modification, Tree-sitter gives wrong AST for source code:

module main

fn main() {
    test := ''
}

Expected Output

Proper Tree-sitter AST should be:

module_clause [0, 0] - [0, 11]
  module_identifier [0, 7] - [0, 11]
function_declaration [2, 0] - [4, 1]
  name: identifier [2, 3] - [2, 7]
  parameters: parameter_list [2, 7] - [2, 9]
  body: block [2, 10] - [4, 1]
    short_var_declaration [3, 1] - [3, 11]
      left: expression_list [3, 1] - [3, 5]
        identifier [3, 1] - [3, 5]
      right: expression_list [3, 9] - [3, 11]
        interpreted_string_literal [3, 9] - [3, 11]

Actual Output

module_clause [0, 0] - [0, 11]
  module_identifier [0, 7] - [0, 11]
function_declaration [2, 0] - [4, 1]
  name: identifier [2, 3] - [2, 7]
  parameters: parameter_list [2, 7] - [2, 9]
  body: block [2, 10] - [4, 1]
    ERROR [3, 1] - [4, 0]
      expression_list [3, 1] - [3, 5]
        identifier [3, 1] - [3, 5]

Note: AST output is given by nvim-treesitter/playground plugin of Neovim.

Steps to Reproduce

You only need to modify assignment of test on line 4.

Open you file and start VLS with:

test := ''

Type whatever you like into string literal:

test := 'this'

Start deleting character you just typee one by one from the end of string literal, until the string is empty:

test := ''

Now you should see the ERROR node in AST.

theoribeiro commented 1 year ago

@SirZenith Been trying out V for the first time and had exactly the same issue with Treesitter on Nvim. Did you find a workaround somehow?

SirZenith commented 1 year ago

@theoribeiro No, this is a tree-sitter-v problem, and need to be fixed in tree-sitter-v.

The only thing I can do now is :e every time that ERROR node shows up.

theoribeiro commented 1 year ago

Sorry for the confusion, is this tree-sitter-v's official repo? https://github.com/nedpals/tree-sitter-v

So you manually sync whenever there are updates or is tree-sitter-v on this repo deprecated?

SirZenith commented 1 year ago

This kind of is tree-sitter-v's official repo. V team decides to manage tree-sitter-v source code here to make VLS update easier for user.

We make changes to tree-sitter-v here. All necessary changes are then sync to the repo you mentioned.

JalonSolov commented 1 year ago

Try https://blog.vosca.dev/meet-v-analyzer/ instead, now that it is released.