From 960d226351f253a78170099889d845ef9ae6ef3f Mon Sep 17 00:00:00 2001 From: iamcco Date: Wed, 25 Mar 2020 15:58:04 +0800 Subject: [PATCH] feat(parser): upgrade vimparser #35 to support eval heredoc method --- package.json | 2 +- src/common/patterns.ts | 2 +- src/common/util.ts | 2 +- src/lib/vimparser.d.ts | 2 +- src/server/buffer.ts | 5 +++++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e58afb8..c1b2482 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vim-language-server", - "version": "1.4.2", + "version": "1.5.0", "description": "vim language server", "keywords": [ "viml", diff --git a/src/common/patterns.ts b/src/common/patterns.ts index a88e6b3..1a8896c 100644 --- a/src/common/patterns.ts +++ b/src/common/patterns.ts @@ -38,7 +38,7 @@ export const notFunctionPattern = [ /^[ \t]*\w+$/, /^[ \t]*"/, /(let|set|colorscheme)[ \t][^ \t]*$/, - /[^([,\\ \t\w#]\w*$/, + /[^([,\\ \t\w#>]\w*$/, /^[ \t]*(hi|highlight)([ \t]+link)?([ \t]+[^ \t]+)*[ \t]*$/, autocmdPattern, ]; diff --git a/src/common/util.ts b/src/common/util.ts index 7cd6f43..6fceb11 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -164,7 +164,7 @@ export function getWordFromPosition( // parse vim buffer export async function handleParse(textDoc: TextDocument | string): Promise<[INode | null, string]> { const text = textDoc instanceof Object ? textDoc.getText() : textDoc; - const tokens = new StringReader(text); + const tokens = new StringReader(text.split(/\r\n|\r|\n/)); try { const node: INode = new VimLParser(true).parse(tokens); return [node, ""]; diff --git a/src/lib/vimparser.d.ts b/src/lib/vimparser.d.ts index 30aba06..cfcb654 100644 --- a/src/lib/vimparser.d.ts +++ b/src/lib/vimparser.d.ts @@ -34,7 +34,7 @@ export declare interface INode { export declare class StringReader { public buf: string[]; public pos: Array<[number, number, number]>; - constructor(str: string) + constructor(lines: string[]) } // tslint:disable-next-line diff --git a/src/server/buffer.ts b/src/server/buffer.ts index 14c3d88..cdce079 100644 --- a/src/server/buffer.ts +++ b/src/server/buffer.ts @@ -87,6 +87,9 @@ const NODE_CURLYNAMEPART = 90; // TODO const NODE_CURLYNAMEEXPR = 91; // TODO const NODE_LAMBDA = 92; const NODE_CONST = 94; +const NODE_EVAL = 95; +const NODE_HEREDOC = 96; +const NODE_METHOD = 97; /* * buffer's completion items @@ -411,6 +414,7 @@ export class Buffer { case NODE_RETURN: case NODE_DELFUNCTION: case NODE_THROW: + case NODE_EVAL: nodeList = nodeList.concat(node.left); break; case NODE_DOT: @@ -483,6 +487,7 @@ export class Buffer { case NODE_ADD: case NODE_SUBTRACT: case NODE_SUBSCRIPT: + case NODE_METHOD: nodeList = nodeList.concat(node.left || []); nodeList = nodeList.concat(node.right || []); break;