Skip to content

Commit b981a91

Browse files
przepompowniaiamcco
authored andcommitted
Another fixes by suggestions from tslint (#24)
* tslint2 - squash it * Rename BuiltinDoc to IBuiltinDoc * Rename Pos to IPos * Rename Node -> INode * Sort key names * Revert "Sort key names" This reverts commit 120fd2f. * object-literal-sort-keys excluded from tslint rules
1 parent 30f442d commit b981a91

File tree

7 files changed

+56
-50
lines changed

7 files changed

+56
-50
lines changed

src/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface IConfig {
3333
}
3434

3535
// builtin-doc
36-
export interface BuiltinDoc {
36+
export interface IBuiltinDoc {
3737
completionItems: {
3838
functions: CompletionItem[]
3939
commands: CompletionItem[]

src/common/util.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import findup from "findup";
33
import path from "path";
44
import { Readable } from "stream";
55
import { CompletionItem, InsertTextFormat, Position, Range, TextDocument } from "vscode-languageserver";
6-
import { Node, StringReader, VimLParser } from "../lib/vimparser";
6+
import { INode, StringReader, VimLParser } from "../lib/vimparser";
77
import { commentPattern, keywordPattern, kindPattern, wordNextPattern, wordPrePattern } from "./patterns";
88

99
export function isSomeMatchPattern(patterns: kindPattern, line: string): boolean {
@@ -57,7 +57,7 @@ export function executeFile(
5757

5858
// error will occur when cp get error
5959
if (!isPassAsText) {
60-
input.pipe(cp.stdin).on("error", () => {});
60+
input.pipe(cp.stdin).on("error", () => { return; });
6161
}
6262

6363
});
@@ -150,19 +150,23 @@ export function getWordFromPosition(
150150

151151
return {
152152
word,
153-
wordLeft: wordLeft && wordLeft[1] ? preSegment.replace(new RegExp(`${wordLeft[1]}$`), word) : `${preSegment}${word}`,
154-
wordRight: wordRight && wordRight[1] ? nextSegment.replace(new RegExp(`^${wordRight[1]}`), word) : `${word}${nextSegment}`,
155153
left: wordLeft && wordLeft[1] || "",
156154
right: wordRight && wordRight[1] || "",
155+
wordLeft: wordLeft && wordLeft[1]
156+
? preSegment.replace(new RegExp(`${wordLeft[1]}$`), word)
157+
: `${preSegment}${word}`,
158+
wordRight: wordRight && wordRight[1]
159+
? nextSegment.replace(new RegExp(`^${wordRight[1]}`), word)
160+
: `${word}${nextSegment}`,
157161
};
158162
}
159163

160164
// parse vim buffer
161-
export async function handleParse(textDoc: TextDocument | string): Promise<[Node | null, string]> {
165+
export async function handleParse(textDoc: TextDocument | string): Promise<[INode | null, string]> {
162166
const text = textDoc instanceof Object ? textDoc.getText() : textDoc;
163167
const tokens = new StringReader(text);
164168
try {
165-
const node: Node = new VimLParser(true).parse(tokens);
169+
const node: INode = new VimLParser(true).parse(tokens);
166170
return [node, ""];
167171
} catch (error) {
168172
return [null, error];

src/lib/vimparser.d.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
export declare interface Pos {
1+
export declare interface IPos {
22
lnum: number;
33
col: number;
44
offset: number;
55
}
66

7-
export declare interface Node {
7+
export declare interface INode {
88
type: number;
9-
pos: Pos;
10-
body: Node[];
9+
pos: IPos;
10+
body: INode[];
1111
ea: {
12-
linepos: Pos
13-
cmdpos: Pos
14-
argpos: Pos
12+
linepos: IPos
13+
cmdpos: IPos
14+
argpos: IPos
1515
cmd: {
1616
name: string,
1717
},
1818
};
19-
cond?: Node;
20-
elseif?: Node[];
21-
_else?: Node;
19+
cond?: INode;
20+
elseif?: INode[];
21+
_else?: INode;
2222
op?: string;
23-
catch?: Node[];
24-
_finally?: Node;
25-
left: Node;
26-
right: Node;
27-
rlist: Node[];
23+
catch?: INode[];
24+
_finally?: INode;
25+
left: INode;
26+
right: INode;
27+
rlist: INode[];
2828
str: string;
2929
value?: any;
30-
endfunction?: Node;
31-
list?: Node[];
30+
endfunction?: INode;
31+
list?: INode[];
3232
}
3333

3434
export declare class StringReader {
@@ -39,5 +39,5 @@ export declare class StringReader {
3939

4040
export declare class VimLParser {
4141
constructor(isNeovim: boolean)
42-
public parse(stringReader: StringReader): Node;
42+
public parse(stringReader: StringReader): INode;
4343
}

src/server/buffer.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CompletionItem, CompletionItemKind, InsertTextFormat } from "vscode-languageserver";
22
import { sortTexts } from "../common/constant";
33
import logger from "../common/logger";
4-
import { Node, Pos } from "../lib/vimparser";
4+
import { INode, IPos } from "../lib/vimparser";
55

66
const log = logger("buffer");
77

@@ -103,7 +103,7 @@ const NODE_CONST = 94;
103103
*/
104104
export interface IFunction {
105105
name: string;
106-
args: Node[];
106+
args: INode[];
107107
startLine: number;
108108
startCol: number;
109109
endLine: number;
@@ -112,7 +112,7 @@ export interface IFunction {
112112

113113
export interface IFunRef {
114114
name: string;
115-
args: Node[];
115+
args: INode[];
116116
startLine: number;
117117
startCol: number;
118118
}
@@ -147,7 +147,7 @@ export class Buffer {
147147
constructor(
148148
private uri: string,
149149
private projectRoot: string,
150-
private node: Node,
150+
private node: INode,
151151
) {
152152
this.updateBufferByNode(this.node);
153153
}
@@ -192,7 +192,7 @@ export class Buffer {
192192
return this.projectRoot === workUri;
193193
}
194194

195-
public updateBufferByNode(node: Node) {
195+
public updateBufferByNode(node: INode) {
196196
this.node = node;
197197
this.resetProperties();
198198
try {
@@ -394,8 +394,8 @@ export class Buffer {
394394
this.envRefs = {};
395395
}
396396

397-
private resolveCompletionItems(nodes: Node | Node[]) {
398-
let nodeList: Node[] = [].concat(nodes);
397+
private resolveCompletionItems(nodes: INode | INode[]) {
398+
let nodeList: INode[] = [].concat(nodes);
399399
while (nodeList.length > 0) {
400400
const node = nodeList.pop();
401401
switch (node.type) {
@@ -509,7 +509,7 @@ export class Buffer {
509509
break;
510510
case NODE_DICT:
511511
nodeList = nodeList.concat(
512-
(node.value || []).map((item: [Node, Node]) => item[1]),
512+
(node.value || []).map((item: [INode, INode]) => item[1]),
513513
);
514514
break;
515515
case NODE_SLICE:
@@ -547,7 +547,7 @@ export class Buffer {
547547
// log.info(`parse_buffer: ${JSON.stringify(this)}`)
548548
}
549549

550-
private takeFunction(node: Node) {
550+
private takeFunction(node: INode) {
551551
const { left, rlist, endfunction } = node;
552552
const name = this.getDotName(left);
553553
if (!name) {
@@ -584,7 +584,7 @@ export class Buffer {
584584
* - let funcName = function()
585585
* - let funcName = funcref()
586586
*/
587-
private takeFunctionByRef(node: Node): boolean {
587+
private takeFunctionByRef(node: INode): boolean {
588588
const { left, right } = node;
589589
if (!right || right.type !== NODE_CALL) {
590590
return;
@@ -629,14 +629,14 @@ export class Buffer {
629629
return false;
630630
}
631631

632-
private takeFuncRef(node: Node) {
632+
private takeFuncRef(node: INode) {
633633
const { left, rlist } = node;
634634
let name = "";
635635
if (left.type === NODE_IDENTIFIER) {
636636
name = left.value;
637637
// <SID>funName
638638
} else if (left.type === NODE_CURLYNAME) {
639-
name = ((left.value || []) as Node[]).map((item) => item.value).join("");
639+
name = ((left.value || []) as INode[]).map((item) => item.value).join("");
640640
} else if (left.type === NODE_DOT) {
641641
name = this.getDotName(left);
642642
}
@@ -675,7 +675,7 @@ export class Buffer {
675675
* - function('funcName')
676676
* - funcref('funcName')
677677
*/
678-
private takeFuncRefByRef(node: Node) {
678+
private takeFuncRefByRef(node: INode) {
679679
const { left, rlist } = node;
680680
const funcNode = rlist && rlist[0];
681681
if (
@@ -717,7 +717,7 @@ export class Buffer {
717717
* - command
718718
* - map
719719
*/
720-
private takeFuncRefByExcmd(node: Node) {
720+
private takeFuncRefByExcmd(node: INode) {
721721
const { pos, str } = node;
722722
if (!str) {
723723
return;
@@ -756,7 +756,7 @@ export class Buffer {
756756
}
757757
}
758758

759-
private takeLet(node: Node) {
759+
private takeLet(node: INode) {
760760
const pos = this.getDotPos(node.left);
761761
const name = this.getDotName(node.left);
762762
if (!pos || !name) {
@@ -785,7 +785,7 @@ export class Buffer {
785785
}
786786
}
787787

788-
private takeFor(nodes: Node[]) {
788+
private takeFor(nodes: INode[]) {
789789
nodes.forEach((node) => {
790790
if (node.type !== NODE_IDENTIFIER || !node.pos) {
791791
return;
@@ -815,7 +815,7 @@ export class Buffer {
815815
});
816816
}
817817

818-
private takeIdentifier(node: Node) {
818+
private takeIdentifier(node: INode) {
819819
const name = this.getDotName(node);
820820
if (!name) {
821821
return;
@@ -847,7 +847,7 @@ export class Buffer {
847847
}
848848
}
849849

850-
private getDotPos(node: Node): Pos | null {
850+
private getDotPos(node: INode): IPos | null {
851851
if (!node) {
852852
return null;
853853
}
@@ -862,7 +862,7 @@ export class Buffer {
862862
return this.getDotPos(left);
863863
}
864864

865-
private getDotName(node: Node) {
865+
private getDotName(node: INode) {
866866
if (
867867
node.type === NODE_IDENTIFIER ||
868868
node.type === NODE_STRING ||
@@ -871,7 +871,7 @@ export class Buffer {
871871
) {
872872
return node.value;
873873
} else if (node.type === NODE_CURLYNAME) {
874-
return ((node.value || []) as Node[]).map((item) => item.value).join("");
874+
return ((node.value || []) as INode[]).map((item) => item.value).join("");
875875
} else if (node.type === NODE_SUBSCRIPT) {
876876
return this.getDotName(node.left);
877877
}

src/server/builtin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
featurePattern,
3232
optionPattern,
3333
} from "../common/patterns";
34-
import { BuiltinDoc } from "../common/types";
34+
import { IBuiltinDoc } from "../common/types";
3535
import { isSomeMatchPattern, pcb } from "../common/util";
3636
import buildDocs from "../docs/builtin-docs.json";
3737
import config from "./config";
@@ -250,7 +250,7 @@ class Builtin {
250250
this.resolveHighlightArgValues();
251251

252252
try {
253-
const data: BuiltinDoc = buildDocs as BuiltinDoc;
253+
const data: IBuiltinDoc = buildDocs as IBuiltinDoc;
254254
this.vimBuiltinFunctionItems = data.completionItems.functions;
255255
this.vimBuiltinFunctionItems.forEach((item) => {
256256
if (!this.vimBuiltinFunctionMap[item.label]) {

src/server/workspaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import URIParser from "vscode-uri";
22

33
import { CompletionItem, Location, Position, Range } from "vscode-languageserver";
44
import { findProjectRoot } from "../common/util";
5-
import { Node } from "../lib/vimparser";
5+
import { INode } from "../lib/vimparser";
66
import { Buffer, IFunction, IIdentifier } from "./buffer";
77
import config from "./config";
88
// import logger from '../common/logger';
@@ -19,7 +19,7 @@ export class Workspace {
1919
return false;
2020
}
2121

22-
public async updateBuffer(uri: string, node: Node) {
22+
public async updateBuffer(uri: string, node: INode) {
2323
if (!node) {
2424
return;
2525
}

tslint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"tslint:recommended"
55
],
66
"jsRules": {},
7-
"rules": {},
7+
"rules": {
8+
"object-literal-sort-keys": false
9+
},
810
"rulesDirectory": []
911
}

0 commit comments

Comments
 (0)