Skip to content

Commit

Permalink
feat(parser): add isNeovim option
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcco committed Mar 8, 2021
1 parent 6a8c69e commit fe373fb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ lsp client config example with coc.nvim
"module": "/path/to/vim-language-server/bin/index.js",
"args": ["--node-ipc"],
"initializationOptions": {
"isNeovim": true, // is neovim, default false
"iskeyword": "@,48-57,_,192-255,-#", // vim iskeyword option
"vimruntime": "", // $VIMRUNTIME option
"runtimepath": "", // vim runtime path separate by `,`
Expand Down Expand Up @@ -95,6 +96,7 @@ lsp client config example with coc.nvim
"command": "vim-language-server",
"args": ["--stdio"],
"initializationOptions": {
"isNeovim": true, // is neovim, default false
"iskeyword": "@,48-57,_,192-255,-#", // vim iskeyword option
"vimruntime": "", // $VIMRUNTIME option
"runtimepath": "", // vim runtime path separate by `,`
Expand All @@ -119,6 +121,7 @@ lsp client config example with coc.nvim

**Note**:

- if you set `isNeovim: true`, command like `fixdel` in vimrc which neovim does not support will report error.
- if you want to speed up index, change `gap` to smaller and `count` to greater, this will cause high CPU usage for some time
- if you don't want to index vim's runtimepath files, set `runtimepath` to `false` and you will not get any suggest from those files.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vim-language-server",
"version": "2.1.2",
"version": "2.1.3",
"description": "vim language server",
"keywords": [
"viml",
Expand Down
1 change: 1 addition & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IIndexes {

// initialization options
export interface IConfig {
isNeovim: boolean;
iskeyword: string;
vimruntime: string;
runtimepath: string[];
Expand Down
3 changes: 2 additions & 1 deletion src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Readable} from "stream";
import {CompletionItem, InsertTextFormat, Position, Range, TextDocument} from "vscode-languageserver";
import {INode, StringReader, VimLParser} from "../lib/vimparser";
import {commentPattern, keywordPattern, kindPattern, wordNextPattern, wordPrePattern} from "./patterns";
import config from '../server/config';

export function isSomeMatchPattern(patterns: kindPattern, line: string): boolean {
return patterns.some((p) => p.test(line));
Expand Down Expand Up @@ -168,7 +169,7 @@ export async function handleParse(textDoc: TextDocument | string): Promise<[INod
const text = textDoc instanceof Object ? textDoc.getText() : textDoc;
const tokens = new StringReader(text.split(/\r\n|\r|\n/));
try {
const node: INode = new VimLParser(true).parse(tokens);
const node: INode = new VimLParser(config.isNeovim).parse(tokens);
return [node, ""];
} catch (error) {
return [null, error];
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import logger from "./common/logger";
connection.onInitialize((param: InitializeParams) => {
const { initializationOptions = {} } = param;
const {
isNeovim,
iskeyword,
runtimepath,
vimruntime,
diagnostic,
suggest,
indexes,
}: {
isNeovim: boolean
iskeyword: string
runtimepath: string
vimruntime: string
Expand All @@ -44,6 +46,7 @@ connection.onInitialize((param: InitializeParams) => {

// config by user's initializationOptions
const conf: IConfig = {
isNeovim: isNeovim || false,
iskeyword: iskeyword || "",
runtimepath: runtimepaths,
vimruntime: (vimruntime || "").trim(),
Expand Down
4 changes: 4 additions & 0 deletions src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default {
}
},

get isNeovim(): boolean {
return conf && conf.isNeovim || false;
},

get iskeyword(): string {
return conf && conf.iskeyword || "";
},
Expand Down

0 comments on commit fe373fb

Please sign in to comment.