Skip to content
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

Add namespace-name suggestions to C# and VB #11968

Merged
merged 3 commits into from
Jun 15, 2016
Merged

Add namespace-name suggestions to C# and VB #11968

merged 3 commits into from
Jun 15, 2016

Conversation

lorcanmooney
Copy link
Contributor

Part of #7213, this adds namespace-name suggestions to C# and VB.

@@ -212,6 +212,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Recommendations
Else
symbols = context.SemanticModel _
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't fully understand this couldBeMergedNamespace thing or it's consequences, but I couldn't hit the positive code path. Am I missing something I'm missing here?

Copy link
Contributor

Choose a reason for hiding this comment

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

The couldBeMergedNamespace thing is an error recovery scenario where GetSymbolInfo returns a bunch of CandidateSymbols that are all namespaces. I tried chasing through source control to find the original related bug but didn't find it, but I don't think you need to worry about it.

@lorcanmooney
Copy link
Contributor Author

Tagging @CyrusNajmabadi, @rchande, @DustinCampbell and @Pilchie as potential reviewers.

@@ -603,6 +603,18 @@ public static bool IsAttributeNameContext(this SyntaxTree syntaxTree, int positi
return syntaxTree.IsTypeContext(position, cancellationToken, semanticModelOpt);
}

public static bool IsNamespaceDeclarationNameContext(this SyntaxTree syntaxTree, int position, CancellationToken cancellationToken)
{
var token = syntaxTree.FindTokenOnLeftOfPosition(position, cancellationToken);
Copy link
Member

Choose a reason for hiding this comment

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

i think you need a ".GetPreviousTokenIfTouchingWord(position)". That way if you're actually on the 'namespace' keyword itself, that we don't think we're in the namespcae name portion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh, you're right about it returning the wrong value when on namespace, but it doesn't seem to be causing any problems. Subsequent checks in the recommendation service must be mitigating it. I'll need to investigate this a bit more.

Copy link
Contributor Author

@lorcanmooney lorcanmooney Jun 13, 2016

Choose a reason for hiding this comment

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

Oh, good catch! It doesn't show up in the simple case, but if we have nested namespaces...

namespace Microsoft
{
    name$$space CodeAnalysis
    {
    }
}

...then it starts suggesting top level namespaces! I think this deserves a few additional tests.

Copy link
Contributor Author

@lorcanmooney lorcanmooney Jun 14, 2016

Choose a reason for hiding this comment

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

Fixed. I've also added a check to bail early on scripts, since apparently they don't support namespace declarations.

@CyrusNajmabadi
Copy link
Member

Overall looking good! I had a few small questions/concerns. Thanks.

@lorcanmooney
Copy link
Contributor Author

@CyrusNajmabadi Thanks, I'll fix those up and add comments as appropriate. Do you have any suggestions regarding my question about the couldBeMergedNamespace path?

@lorcanmooney
Copy link
Contributor Author

@CyrusNajmabadi I've updated the PR based your feedback. I've fixed everything except the IsNonIntersectingNamespace method, since (a) it will re-introduce a problem I was having with incorrect symbols a while ago (see #7213), (b) I'm not convinced the effort is worth it, and (c) it's late here and I need some sleep! I hope it won't block the merge.

@CyrusNajmabadi
Copy link
Member

test vsi please

@CyrusNajmabadi
Copy link
Member

👍

Nice job!

@Pilchie
Copy link
Member

Pilchie commented Jun 14, 2016

@rchande and @dotnet/roslyn-ide can you take a look?

}

return SpecializedCollections.EmptyEnumerable<CompletionItem>();
}

private async Task<IEnumerable<CompletionItem>> GetSnippetCompletionItemsAsync(Workspace workspace, SemanticModel semanticModel, int position, TextSpan itemSpan, bool isPreProcessorContext, CancellationToken cancellationToken)
private async Task<IEnumerable<CompletionItem>> GetSnippetCompletionItemsAsync(Workspace workspace, SemanticModel semanticModel, TextSpan itemSpan, bool isPreProcessorContext, CancellationToken cancellationToken)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, unrelated. I noticed the param was unused as I was passing through. Should I revert it?

Copy link
Member

Choose a reason for hiding this comment

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

Don't need to revert this.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it's fine.

@rchande
Copy link
Contributor

rchande commented Jun 14, 2016

👍

@lorcanmooney
Copy link
Contributor Author

I don't have access to the vsi_p2 test failure results, so please let me know if there's something I need to investigate.

@CyrusNajmabadi
Copy link
Member

Nope. It's a known issue.

@CyrusNajmabadi CyrusNajmabadi merged commit 35a07f6 into dotnet:master Jun 15, 2016
@CyrusNajmabadi
Copy link
Member

Thanks Lorcan!

@lorcanmooney lorcanmooney deleted the issue7213-namespaces branch July 9, 2016 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants