Skip to content

Ctags support for visual basic .net #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ctagsdotd/vbnet.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See additional-language.ctags for maintaining this file. The type member specification for VB.NET can be found at https://learn.microsoft.com/en-us/dotnet/visual-basic/reference/language-specification/type-members
--langdef=vbnet
--langmap=vbnet:.vb
--regex-vbnet=/^(?i)\s*(?:(?:Public|Private|Protected|Friend|Overloads|Overrides|Overridable|NotOverridable|MustOverride|Shared|Shadows|Async|Iterator)\s+)*\s*(?:Function|Sub)\s+([A-Z_0-9\[\]]*)\(.*?\)\s*(?:As\s+[\w.]+)?/\1/m,method/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I have ~0 Visual Basic knowledge). Could you explain why this is using m,method instead of f,function? For example, Rust supports both methods and functions, so the output of ctags --list-kinds-full=Rust has both P method and f function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actually two types in VB.NET Subs and Functions. The difference between them is that Functions have a return value while Subs do not. And since the [language-specification] (https://learn.microsoft.com/en-us/dotnet/visual-basic/reference/language-specification/type-members)calls both methods, I opted for that one.

--regex-vbnet=/^(?i)\s*(?:(?:Default|Public|Private|Protected|Friend|Overloads|Overrides|Overridable|NotOverridable|MustOverride|Shared|Shadows|WriteOnly|ReadOnly|Iterator)\s+)*\s*(?:Property)\s+([A-Z_0-9\[\]]*)\s+As\s+/\1/p,property/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this regex have an extra check for Let/Set/Get?

Looking at one of the code examples here:

https://learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/writing-a-property-procedure

Property Let Names(intX As Integer, intY As Integer, varZ As Variant) 
 ' Statement here. 
End Property 
 
Property Get Names(intX As Integer, intY As Integer) As Variant 
 ' Statement here. 
End Property 

This regex seems like it'll misidentify Let/Get/Set as the name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link you provided is for VBA (Visual Basic for Applications). While this implementation is supposed to add support for Visual Basic (.NET).
My source for the implementation was: https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/property-statement

--regex-vbnet=/^(?i)\s*(?:(?:Public|Private|Protected|Friend|Shared|Shadows|Custom)\s+)*\s*(?:Event)\s+([A-Z_0-9\[\]]*)/\1/E,event/
--regex-vbnet=/^(?i)\s*(?:(?:Public|Private|Protected|Friend|Shadows|MustInherit|NotInheritable|Partial)\s+)*\s*(?:Class)\s+([A-Z_0-9\[\]]*)/\1/c,class/
--regex-vbnet=/^(?i)\s*(?:(?:Public|Private|Protected|Friend|Shadows)\s+)*\s*(?:Interface)\s+([A-Z_0-9\[\]]*)/\1/i,interface/
--regex-vbnet=/^(?i)\s*(?:(?:Public|Private|Protected|Friend|Shadows|Partial)\s+)*\s*(?:Structure)\s+([A-Z_0-9\[\]]*)/\1/s,struct/
--regex-vbnet=/^(?i)\s*(?:(?:Public|Private|Protected|Friend|Shadows)\s+)*\s*(?:Enum)\s+([A-Z_0-9\[\]]*)/\1/g,enum/
--regex-vbnet=/^(?i)\s*(?:(?:Public|Friend)\s+)*\s*(?:Module)\s+([A-Z_0-9\[\]]*)/\1/c,class/
--regex-vbnet=/^(?i)\s*(?:(?:Public|Overloads|Shared|Shadows|Widening|Narrowing)\s+)*\s*(?:Operator)\s+([\+\-\*\/\\=<>a-z]+)/\1/m,method/
2 changes: 1 addition & 1 deletion language-mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
)

var SupportedLanguages = [...]string{"Basic", "C", "C#", "C++", "Clojure", "Cobol", "CSS", "CUDA", "D", "Elixir", "elm", "Erlang", "Go", "GraphQL", "Groovy", "haskell", "Java", "JavaScript", "Jsonnet", "kotlin", "Lisp", "Lua", "MatLab", "ObjectiveC", "OCaml", "Pascal", "Perl", "Perl6", "PHP", "Powershell", "Protobuf", "Python", "R", "Ruby", "Rust", "scala", "Scheme", "Sh", "swift", "SystemVerilog", "Tcl", "Thrift", "typescript", "tsx", "Verilog", "VHDL", "Vim"}
var SupportedLanguages = [...]string{"Basic", "C", "C#", "C++", "Clojure", "Cobol", "CSS", "CUDA", "D", "Elixir", "elm", "Erlang", "Go", "GraphQL", "Groovy", "haskell", "Java", "JavaScript", "Jsonnet", "kotlin", "Lisp", "Lua", "MatLab", "ObjectiveC", "OCaml", "Pascal", "Perl", "Perl6", "PHP", "Powershell", "Protobuf", "Python", "R", "Ruby", "Rust", "scala", "Scheme", "Sh", "swift", "SystemVerilog", "Tcl", "Thrift", "typescript", "tsx", "vbnet", "Verilog", "VHDL", "Vim"}

func ListLanguageMappings(ctx context.Context, bin string) (map[string][]string, error) {
if bin == "" {
Expand Down