Skip to content

Commit

Permalink
feat: use improved lua parser and fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed May 1, 2022
1 parent bbaca07 commit 6650989
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 94 deletions.
2 changes: 1 addition & 1 deletion ftplugin/lua.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let b:doge_patterns = doge#buffer#get_patterns()
" Matches regular function expressions, definitions and class methods.
" ------------------------------------------------------------------------------
let s:function_and_class_method_pattern = {
\ 'nodeTypes': ['function', 'function_definition'],
\ 'nodeTypes': ['function', 'function_declaration', 'function_definition'],
\ 'parameters': {
\ 'format': '@param {name} !description',
\ },
Expand Down
112 changes: 24 additions & 88 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
]
},
"dependencies": {
"@muniftanjim/tree-sitter-lua": "^0.0.10",
"tree-sitter": "^0.20.0",
"tree-sitter-bash": "^0.19.0",
"tree-sitter-c": "^0.20.1",
"tree-sitter-cpp": "^0.20.0",
"tree-sitter-java": "^0.19.1",
"tree-sitter-lua": "^1.6.2",
"tree-sitter-php": "^0.19.0",
"tree-sitter-python": "^0.19.0",
"tree-sitter-ruby": "^0.19.0",
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Bash from 'tree-sitter-bash';
import C from 'tree-sitter-c';
import CPP from 'tree-sitter-cpp';
import Java from 'tree-sitter-java';
import Lua from 'tree-sitter-lua';
import Lua from '@muniftanjim/tree-sitter-lua';
import PHP from 'tree-sitter-php';
import Python from 'tree-sitter-python';
import Ruby from 'tree-sitter-ruby';
Expand Down
9 changes: 7 additions & 2 deletions src/parsers/lua.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CustomParserService } from './custom-parser-service.interface';

enum NodeType {
FUNCTION = 'function',
FUNCTION_DECLARATION = 'function_declaration',
FUNCTION_DEFINITION = 'function_definition',
}

Expand All @@ -26,7 +27,8 @@ export class LuaParserService
) {
switch (node.type) {
case NodeType.FUNCTION:
case NodeType.FUNCTION_DEFINITION: {
case NodeType.FUNCTION_DEFINITION:
case NodeType.FUNCTION_DECLARATION: {
this.result = { name: null, parameters: [] };
this.runNodeParser(this.parseFunction, node);
break;
Expand Down Expand Up @@ -71,7 +73,10 @@ export class LuaParserService
childNode.children
.filter((n: SyntaxNode) => n.type === 'identifier')
.forEach((cn: SyntaxNode) => {
this.result.parameters.push({ name: cn.text });
const name = cn.text;
if (name !== 'self') {
this.result.parameters.push({ name });
}
});
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vim-doge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ declare module 'tree-sitter-c';
declare module 'tree-sitter-cpp';
declare module 'tree-sitter-bash';
declare module 'tree-sitter-ruby';
declare module 'tree-sitter-lua';
declare module '@muniftanjim/tree-sitter-lua';
declare module 'tree-sitter-java';
declare module 'tree-sitter-rust';

0 comments on commit 6650989

Please sign in to comment.