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

Conversation

sagi1623
Copy link

As I mentioned here I was unable to isntall sg and it seems to me that I would need to reinstall windows to be able to properly set up the environment to develop.

I have followed this guideline to add support for symbol search for visual basic .net and without a proper testing environment I have no idea if I did the right thing or not 😄.
I would kindly ask you @olafurpg or somebody else from Sourcegraph to take a look at this draft PR and help me test it and make it to the main branch if possible.

Notes:

  • I have not added support for fields as it seems to me that they have the same format as variable declarations. So, with a simple regex I would have created a lot of noise by reporting also variables as fields.
  • https://github.com/sourcegraph/go-ctags/blob/main/ctagsdotd/additional-languages.ctags mentions to check if ctagsKindToLSPSymbolKind handles all the ctag kinds, however I was not able to find the correct place to check it so the PR might be missing something.

@keegancsmith
Copy link
Member

cc @olafurpg @SuperAuguste

@sagi1623
Copy link
Author

sagi1623 commented Nov 2, 2023

Hey @olafurpg,
I have finally signed the CLA, do you think we could try to get this PR moving again?

--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/
--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

@@ -0,0 +1,12 @@
# See additional-language.ctags for maintaining this file
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Add a link to https://learn.microsoft.com/en-us/dotnet/visual-basic/reference/language-specification/type-members in the comment so that is easier for someone to cross-check this.

--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/
--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/
--regex-vbnet=/^(?i)\s*(?:(?:Public|Private|Protected|Friend|Shared|Shadows|Custom)\s+)*\s*(?:Event)\s+([A-Z_0-9\[\]]*)/\1/e,event/
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the output of ctags --list-kinds-full from universal-ctags, I see that it has E event, e enumerator and g enum. So I recommend following the same here, instead of using e,event, e,enum (Based on the distinct short codes in the ctags --list-kinds-full output, I suspect using the same short code for different kinds might cause some problem, but I haven't tested it.)

# See additional-language.ctags for maintaining this file
--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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants