Skip to content

Add Visual Basic support #26

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

Merged
merged 14 commits into from
Jun 5, 2023

Conversation

sagi1623
Copy link
Contributor

@sagi1623 sagi1623 commented May 22, 2023

Previously, scip-dotnet only supported C#. This PR adds support for Visual Basic as well. We are able to reuse a lot of code from the C# indexer by extracting shared logic related to formatting symbols.

@sagi1623 sagi1623 mentioned this pull request May 22, 2023
Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

@sagi1623 Thank you so much for this contribution! It's fantastic that we can support Visual Basic with so much code reuse. Nice job porting all the tests from C# to Visual Basic 👏🏻

Only minor suggestions, I am happy to merge this PR once those are addressed.

var walker = new ScipCSharpSyntaxWalker(symbolFormatter, semanticModel);
walker.Visit(root);
}
else
Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to guard against this here

Suggested change
else
else if (language == "Visual Basic")

/// <summary>
/// Walks a single VisualBasic syntax tree and produces a SCIP <code>Document</code>.
/// </summary>
public class ScipVisualBasicSyntaxWalker : VisualBasicSyntaxWalker
Copy link
Member

Choose a reason for hiding this comment

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

Impressive how much code reuse we can do between C# and Visual Basic!

_doc = doc;
_options = options;
_globals = globals;
_languagePrefix = _doc.Language == "C#" ? "cs" : "vb";
Copy link
Member

Choose a reason for hiding this comment

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

nit: I had to check how this variable was used to understand what it does, this name might be clearer

Suggested change
_languagePrefix = _doc.Language == "C#" ? "cs" : "vb";
_markdownCodeFenceLanguage = _doc.Language == "C#" ? "cs" : "vb";

@@ -13,10 +13,8 @@ namespace ScipDotnet;
/// </summary>
public class ScipIndexer
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public class ScipIndexer
public class ScipProjectIndexer

/// <summary>
/// Creates SCIP <code>Document</code> based on provided symbols.
/// </summary>
public class ScipSymbolFormatter
Copy link
Member

@olafurpg olafurpg May 23, 2023

Choose a reason for hiding this comment

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

My initial interpretation of the name ScipSymbolFormatter was that it formats SCIP symbols like this interface we have in Go https://sourcegraph.com/github.com/sourcegraph/scip/-/blob/bindings/[go/scip/symbol_formatter.go?L10](https://www.golinks.io/scip/symbol_formatter.go?L10?trackSource=github)

I propose we rename this class into something else to make it clearer that this class does more than just format symbols

Suggested change
public class ScipSymbolFormatter
public class ScipDocumentIndexer

I also propose we rename ScipIndexer into ScipProjectIndexer

@sagi1623 sagi1623 force-pushed the AraGimLeg/VisualBasic-support branch from ab76842 to c9f4c57 Compare May 24, 2023 20:56
@sagi1623
Copy link
Contributor Author

@olafurpg,
I have applied the suggestions you had, and I have also added in the last commit, support for indexing individual visual basic projects.
Now I would have a few other questions for you if possible:

  • I have tried to follow the guide for adding support for a new language, however my windows is misbehaving and I am unable to install sg. Because of that I would only be able to open the PRs blindly without testing, which I am not super comfortable with. May I ask you or somebody from SourceGraph to do that part?
  • As VisualBasic declared member names are case-insensitive, it can happen that we index for example a parameter as definition scip-dotnet nuget . . VBMain/SomeClass#Method().(SomeParameter) and later reference as reference scip-dotnet nuget . . VBMain/SomeClass#Method().(SoMePaRaMetEr).
    My question here is if SCIP symbol names are case sensitive or not? Will the engine know that it is the same symbol or not?
    In case it is case sensitive, do you think it is at indexing that we need to handle this (for example convert the names to lower) or the engine should take care about it when loading the code intel? (I guess it depends if there are other languages with the same behavior)

@olafurpg
Copy link
Member

May I ask you or somebody from SourceGraph to do that part?

Do you have a ready diff I can test locally? I'm happy to ensure we get Visual Basic support added.

My question here is if SCIP symbol names are case sensitive or not? Will the engine know that it is the same symbol or not?

Good question. SCIP symbols are case sensitive so I recommend we lowercase symbols during indexing time.

@sagi1623
Copy link
Contributor Author

Do you have a ready diff I can test locally? I'm happy to ensure we get Visual Basic support added.

Not yet, I will not have time next week to work on it. If you don't mind waiting, I can try to do it the week after and send you the PRs for testing and review?

Good question. SCIP symbols are case sensitive so I recommend we lowercase symbols during indexing time.

Do you think we could merge this PR to limit the scope of it and I can create a new one some time later to tackle the problem of case insensitivity?

@olafurpg
Copy link
Member

Not yet, I will not have time next week to work on it. If you don't mind waiting, I can try to do it the week after and send you the PRs for testing and review?

Sounds good. FYI, I'm doing cross-Atlantic travel for work June 4-7th so I may be slow to respond that week.

Do you think we could merge this PR to limit the scope of it and I can create a new one some time later to tackle the problem of case insensitivity?

That's fine. I am OK with merging this PR once the CI is green. It might help to rebase on top of main now that the flaky tests have been fixed thanks to your PR #27 😄

@sagi1623 sagi1623 force-pushed the AraGimLeg/VisualBasic-support branch from 2f9532f to 5ed9b04 Compare June 4, 2023 12:47
Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻 Thank you so much for this contribution! This is a great improvement 😄

@@ -248,7 +253,7 @@ private string FormatDocument(Index index, Document document)
if (isDefinition)
{
var info = symtab.GetValueOrDefault(occurrence.Symbol, new SymbolInformation());
var prefix = "//" + indent + new String(' ', length + 1);
var prefix = commentChar + indent + new String(' ', length + 1);
Copy link
Member

Choose a reason for hiding this comment

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

Alternative solution, not a request to change, just thinking out loud

``suggestion
var prefix = commentChar + indent + new String(' ', length + commentChar.length - 1);

@sagi1623
Copy link
Contributor Author

Hello @olafurpg,

Coming back to our discussion regarding VbNet being case insensitive.
Actually it was a false alarm from me (sorry for that).
After revisiting the topic and testing it a bit it I realised that there is nothing to do, it works out of the box.
As we work with the semantic model and retrieve the symbols from there, it will always contain the fully defined name of the symbol as declared.
For example:
Public Sub New(ByVal wEiRdCaSiNg As Long) -> The definition will be VBMain/Classes#.ctor().(wEiRdCaSiNg)
And if it is used later with a different casing like Property = WeIrDcAsInG the retrieved symbol will still have the original wEiRdCaSiNg name so the reference will be -> VBMain/Classes#.ctor().(wEiRdCaSiNg)

@olafurpg
Copy link
Member

@sagi1623 good to confirm that. Should we update the indexer to emit case sensitive names?

@sagi1623
Copy link
Contributor Author

@sagi1623 good to confirm that. Should we update the indexer to emit case sensitive names?

Could you please clarify what do you mean by that?

I think that the current behaviour is correct. I mean C# is case sensitive so with whichever casing you declare a symbol you will need to reference it with the same one. For VbNet that is not the case, if you declare the symbol with one casing, you can reference it with another one. However, this difference is not syntax level. On a semantic level it will be the same symbol.
As Roslyn will give the name from the symbol, which got it from the declaration, we will always use the same casing trough the whole indexing process and I think because of this everything will work as expected once the indexing results are uploaded.

Am I missing something?

And I will soon add a new case in the snapshot project, that will document the current behaviour and should act as a safety net in case the implementation changes in the future.

@olafurpg
Copy link
Member

I thought we used all-lowercase for VB symbols but looking at the original discussion it seems like we left this change for a future PR. I agree the current behavior is correct and there's nothing we need to do 👍🏻

@sagi1623
Copy link
Contributor Author

I thought we used all-lowercase for VB symbols but looking at the original discussion it seems like we left this change for a future PR. I agree the current behavior is correct and there's nothing we need to do 👍🏻

Yes we said it will come in a future PR.
Once again sorry for creating the confusion.
I have created a PR to document the behaviour and to have a test case for the future.

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.

2 participants