Skip to content

Reduce allocations in the CodeLens providers #719

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 8 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 2 additions & 3 deletions src/PowerShellEditorServices.Host/CodeLens/CodeLensFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ private async Task HandleCodeLensRequest(
CodeLensRequest codeLensParams,
RequestContext<LanguageServer.CodeLens[]> requestContext)
{
var scriptFile =
_editorSession.Workspace.GetFile(
codeLensParams.TextDocument.Uri);
ScriptFile scriptFile = _editorSession.Workspace.GetFile(
Copy link
Contributor

Choose a reason for hiding this comment

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

I like. The rule for using var on my team is this - use var when the type of the RHS is obvious i.e. it's a literal, a new statement or type-cast. And also when required - anonymous types. Do not use var when the type is not obvious, which it usually isn't when invoking a method (or reading a property).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% agreed on that rule!

Copy link
Member

Choose a reason for hiding this comment

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

Also 100% agree!

codeLensParams.TextDocument.Uri);

CodeLens[] codeLensResults = ProvideCodeLenses(scriptFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private CodeLens[] GetPesterLens(
public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
{
var lenses = new List<CodeLens>();
foreach (var symbol in _symbolProvider.ProvideDocumentSymbols(scriptFile))
foreach (SymbolReference symbol in _symbolProvider.ProvideDocumentSymbols(scriptFile))
Copy link
Member

Choose a reason for hiding this comment

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

This only calls ProvideDocumentSymbols once and iterates through the result, right?

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 think so, yes. Why do you ask?

Copy link
Member

Choose a reason for hiding this comment

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

spoke to @SeeminglyScience about this. We're good

{
if (symbol is PesterSymbolReference pesterSymbol)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task<CodeLens> ResolveCodeLensAsync(
ScriptFile[] references = _editorSession.Workspace.ExpandScriptReferences(
codeLens.File);

var foundSymbol = _editorSession.LanguageService.FindFunctionDefinitionAtLocation(
SymbolReference foundSymbol = _editorSession.LanguageService.FindFunctionDefinitionAtLocation(
codeLens.File,
codeLens.ScriptExtent.StartLineNumber,
codeLens.ScriptExtent.StartColumnNumber);
Expand Down