Skip to content

Commit

Permalink
fix: adjust startPosition logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Jun 15, 2022
1 parent 51c7a6d commit d11695e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion autoload/doge/pattern.vim
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function! doge#pattern#generate(pattern) abort
let l:comment_indent = 0
if has_key(l:tokens, 'startPosition')
" If the startPosition has been given, we'll use that.
let l:comment_lnum_insert_position = max([0, l:tokens['startPosition'] - 1])
let l:comment_lnum_insert_position = l:tokens['startPosition']
else
" by default we'll insert 1 line above the declaration.
let l:comment_lnum_insert_position = line('.') - 1
Expand Down
11 changes: 1 addition & 10 deletions src/parsers/base-parser.service.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import { SyntaxNode } from 'tree-sitter';

export class BaseParserService {
private defaultResult: Record<string, any> = {};

protected result: Record<string, any> = {};

protected done = false;

public setDefaultResult(result: Record<string, any>) {
this.defaultResult = result;
}

public output(): void {
if (Object.keys(this.result).length > 0) {
console.log(JSON.stringify({
...this.defaultResult,
...this.result
}));
console.log(JSON.stringify(this.result));
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/parsers/cpp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export class CppParserService extends BaseParserService implements CustomParserS
this.nodeTypes.includes(node.type) &&
this.done === false
) {
this.setDefaultResult({
startPosition: node.startPosition.row,
});

switch (node.type) {
case NodeType.TEMPLATE_DECLARATION: {
const childNode: SyntaxNode = node.children
Expand All @@ -50,6 +46,7 @@ export class CppParserService extends BaseParserService implements CustomParserS
? this.getTypeParameters(node.parent)
: [],
name: null,
startPosition: node.startPosition.row,
parameters: [],
returnType: null,
};
Expand Down

0 comments on commit d11695e

Please sign in to comment.