Skip to content

On-the-fly-docs -- Add better testing and provide more context for more cases #78148

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

akhera99
Copy link
Member

@akhera99 akhera99 commented Apr 14, 2025

Fixes #78102

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 14, 2025
@akhera99 akhera99 removed the VSCode label Apr 14, 2025
@akhera99 akhera99 marked this pull request as ready for review April 16, 2025 19:31
@akhera99 akhera99 requested a review from a team as a code owner April 16, 2025 19:31
var solution = workspace.CurrentSolution;
var document = solution.Projects.First().Documents.First();

var syntaxTree = await document.GetSyntaxTreeAsync();
var semanticModel = await document.GetSemanticModelAsync();

var methodInvocation = syntaxTree!.GetRoot()
return (solution, document, semanticModel!, syntaxTree!);
Copy link
Member

Choose a reason for hiding this comment

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

  1. this needs to return the workspace. THe caller needs to dispose it at the end.
  2. no need to return document and solution, the former gives you the latter.
  3. no need to return semantic model and syntax tree, the former gives you the latter.
  4. tuples names are camelCased :)

using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.QuickInfo;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.QuickInfo;
Copy link
Member

Choose a reason for hiding this comment

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

needed?

Func<SyntaxTree, SemanticModel, ISymbol> getSymbol,
string? expectedText = null,
bool expectAllNull = false,
int resultIndex = 0)
Copy link
Member

Choose a reason for hiding this comment

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

instead of resultIndex, just pass the N results you expect through here. the test can assert the right count of result contexts vs expected reuslts, then check all N of them.

Comment on lines 634 to 637
var (solution, _, semanticModel, syntaxTree) = await SetupWorkspaceAsync(testCode);

var symbol = getSymbol(syntaxTree, semanticModel);
var result = OnTheFlyDocsUtilities.GetAdditionalOnTheFlyDocsContext(solution, symbol);
Copy link
Member

Choose a reason for hiding this comment

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

probably easier to just extract this out to a helper. Then have TestSuccessAsync and TestFailureAsync helper that uses this. instead of trying to jam all values into 'expecteText/expectAllNull/resultIndex' parameterization approach.


await TestInvocationContextAsync(testCode, customTypeText, resultIndex: 0);
await TestInvocationContextAsync(testCode, customStructText, resultIndex: 1);
}
Copy link
Member

Choose a reason for hiding this comment

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

the cleanup is very appreciated. consider calling this like so:

Suggested change
}
await TestInvocationContextAsync(testCode, customTypeText, customStructText);

}

private static async Task TestSymbolContextAsync(
string testCode,
Copy link
Member

Choose a reason for hiding this comment

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

add [StringSyntax] attribute here.

{
return TestSymbolContextAsync(
testCode,
(syntaxTree, semanticModel) => GetMethodSymbol(syntaxTree, semanticModel),
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
(syntaxTree, semanticModel) => GetMethodSymbol(syntaxTree, semanticModel),
GetMethodSymbol,

expectedText,
expectAllNull,
resultIndex);
}
Copy link
Member

Choose a reason for hiding this comment

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

can create single helper fort hsi and the above method that generically is passed a <TSyntaxNode> type arg.

{
return elementInfo;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

whats' the general logic/thinking here? I don't relaly get the idea of why we're just getting the first thing and returning, and ending with that. for example, if i have (string s, Customer c) why do i only get relevant file info for string and nto Customer?

{
return constraintInfo;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

same question/concern

if (typeSymbol is IArrayTypeSymbol arrayTypeSymbol)
{
typeSymbol = arrayTypeSymbol.ElementType;
}
Copy link
Member

Choose a reason for hiding this comment

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

IPointerTypeSymbol as well.

{
typeSymbol = namedTypeSymbol.TypeArguments[0];
}

var typeSyntaxReference = typeSymbol.DeclaringSyntaxReferences.FirstOrDefault();
Copy link
Member

Choose a reason for hiding this comment

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

same here. what does this mean for partial types?

@CyrusNajmabadi
Copy link
Member

Glad to see tests :)

Consider adding tests taht show what happens when the call is in varying contexts: property initializers, accessors, constructors, operators, indexers, methods, local functions, top level functions, lambdas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On-the-fly-docs context testing
2 participants