-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: copy over PR #313 due to unrelated histories and adjust logic
- Loading branch information
Showing
16 changed files
with
808 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
" ============================================================================== | ||
" The PHP documentation should follow the 'phpdoc' conventions. | ||
" see https://www.phpdoc.org | ||
" ============================================================================== | ||
|
||
let s:save_cpo = &cpoptions | ||
set cpoptions&vim | ||
|
||
let b:doge_parser = 'cs' | ||
let b:doge_insert = 'above' | ||
|
||
let b:doge_supported_doc_standards = doge#buffer#get_supported_doc_standards(['csxml']) | ||
let b:doge_doc_standard = doge#buffer#get_doc_standard('cs') | ||
let b:doge_patterns = doge#buffer#get_patterns() | ||
|
||
" ============================================================================== | ||
" | ||
" Define the doc standards. | ||
" | ||
" ============================================================================== | ||
|
||
call doge#buffer#register_doc_standard('csxml', [ | ||
\ { | ||
\ 'nodeTypes': ['method_declaration', 'operator_declaration', 'delegate_declaration'], | ||
\ 'parameters': { | ||
\ 'format': '<param name="{name}">!description</param>' | ||
\ }, | ||
\ 'template': [ | ||
\ '/// <summary>', | ||
\ '/// !description', | ||
\ '/// </summary>', | ||
\ '%(parameters|/// {parameters})%', | ||
\ '%(hasReturn|/// <returns>!description</returns>)%', | ||
\ ], | ||
\ }, | ||
\ { | ||
\ 'nodeTypes': ['constructor_declaration'], | ||
\ 'parameters': { | ||
\ 'format': '<param name="{name}">!description</param>' | ||
\ }, | ||
\ 'template': [ | ||
\ '/// <summary>', | ||
\ '/// !description', | ||
\ '/// </summary>', | ||
\ '%(parameters|/// {parameters})%', | ||
\ ], | ||
\ }, | ||
\ { | ||
\ 'nodeTypes': ['class_declaration', 'variable_declaration', 'property_declaration', 'field_declaration', 'enum_declaration'], | ||
\ 'template': [ | ||
\ '/// <summary>', | ||
\ '/// !description', | ||
\ '/// </summary>', | ||
\ ], | ||
\ }, | ||
\]) | ||
|
||
let &cpoptions = s:save_cpo | ||
unlet s:save_cpo |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { SyntaxNode } from 'tree-sitter'; | ||
import { BaseParserService } from './base-parser.service'; | ||
import { CustomParserService } from './custom-parser-service.interface'; | ||
|
||
enum NodeType { | ||
METHOD_DECLARATION = 'method_declaration', | ||
CLASS_DECLARATION = 'class_declaration', | ||
VARIABLE_DECLARATION = 'variable_declaration', | ||
PROPERTY_DECLARATION = 'property_declaration', | ||
CONSTRUCTOR_DECLARATION = 'constructor_declaration', | ||
CONSTANT_DECLARATION = 'field_declaration', | ||
OPERATOR_DECLARATION = 'operator_declaration', | ||
DELEGATE_DECLARATION = 'delegate_declaration', | ||
ENUM_DECLARATION = 'enum_declaration' | ||
} | ||
|
||
export class CSharpParserService extends BaseParserService implements CustomParserService { | ||
constructor( | ||
readonly rootNode: SyntaxNode, | ||
private readonly lineNumber: number, | ||
private readonly nodeTypes: string[], | ||
) { | ||
super(); | ||
} | ||
|
||
public traverse(node: SyntaxNode): void { | ||
if ( | ||
node.startPosition.row !== this.lineNumber | ||
|| !this.nodeTypes.includes(node.type) | ||
|| this.done !== false | ||
) { | ||
if (node.childCount > 0) { | ||
node.children.forEach((childNode: SyntaxNode) => { | ||
this.traverse(childNode); | ||
}); | ||
} | ||
|
||
return; | ||
} | ||
|
||
switch (node.type) { | ||
case NodeType.METHOD_DECLARATION: | ||
case NodeType.DELEGATE_DECLARATION: | ||
case NodeType.OPERATOR_DECLARATION: | ||
this.result = { parameters: [], hasReturn: true }; | ||
this.runNodeParser(this.parseFunction, node); | ||
break; | ||
|
||
case NodeType.CONSTRUCTOR_DECLARATION: | ||
this.result = { parameters: [] }; | ||
this.runNodeParser(this.parseConstructor, node); | ||
break; | ||
|
||
case NodeType.VARIABLE_DECLARATION: | ||
case NodeType.ENUM_DECLARATION: | ||
case NodeType.CONSTANT_DECLARATION: | ||
case NodeType.PROPERTY_DECLARATION: | ||
case NodeType.CLASS_DECLARATION: | ||
this.result = {}; | ||
this.forceOutput = true; | ||
break; | ||
|
||
|
||
default: | ||
console.error(`Unable to handle node type: ${node.type}`); | ||
break; | ||
} | ||
} | ||
|
||
private parseFunction(node: SyntaxNode): void { | ||
node.children.forEach((childNode: SyntaxNode) => { | ||
if (childNode.type === 'void_keyword') { | ||
this.result.hasReturn = false; | ||
} else if (childNode.type === 'parameter_list') { | ||
this.extractParamsFromList(childNode); | ||
} | ||
}); | ||
} | ||
|
||
private parseConstructor(node: SyntaxNode): void { | ||
node.children.forEach((childNode: SyntaxNode) => { | ||
if (childNode.type === 'parameter_list') { | ||
this.extractParamsFromList(childNode); | ||
} | ||
}); | ||
} | ||
|
||
private extractParamsFromList(parameterList: SyntaxNode) { | ||
parameterList.children.forEach((parameterNode: SyntaxNode) => { | ||
if (parameterNode.type === 'parameter') { | ||
this.result.parameters.push({ | ||
name: parameterNode.children?.filter((n: SyntaxNode) => n.type === 'identifier').pop()?.text | ||
}); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# ============================================================================== | ||
# Construcor without params | ||
# ============================================================================== | ||
Given cs (constructor without params): | ||
public class MyClass | ||
{ | ||
public MyClass() | ||
{ | ||
} | ||
} | ||
|
||
Do (run doge): | ||
:3\<CR> | ||
\<C-d> | ||
|
||
Expect cs (constructor with summary only): | ||
public class MyClass | ||
{ | ||
/// <summary> | ||
/// [TODO:description] | ||
/// </summary> | ||
public MyClass() | ||
{ | ||
} | ||
} | ||
|
||
# ============================================================================== | ||
# Constructor with params | ||
# ============================================================================== | ||
Given cs (constructor without params): | ||
public class MyClass | ||
{ | ||
public MyClass(string arg1, MyClass arg2) | ||
{ | ||
} | ||
} | ||
|
||
Do (run doge): | ||
:3\<CR> | ||
\<C-d> | ||
|
||
Expect cs (constructor with summary only): | ||
public class MyClass | ||
{ | ||
/// <summary> | ||
/// [TODO:description] | ||
/// </summary> | ||
/// <param name="arg1">[TODO:description]</param> | ||
/// <param name="arg2">[TODO:description]</param> | ||
public MyClass(string arg1, MyClass arg2) | ||
{ | ||
} | ||
} |
Oops, something went wrong.