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

Resurrect support to resolve aliased references #1656

Merged
merged 6 commits into from
Jan 8, 2022

Conversation

andyleejordan
Copy link
Member

This work was spawned by a skipped unit test that "indicated a bug in the product code." The bug was that the support was removed, but could be brought back fairly simply now that the pipeline threading work is finished.

Base automatically changed from andschwa/language-tests to master January 7, 2022 20:19
In ancient times, commit 633e36b
implemented support for aliases when finding references. This was
removed during the OmniSharp rewrite because it needed the pipeline
thread, which was not yet available. With that work complete, this can
now be resurrected.
@andyleejordan andyleejordan force-pushed the andschwa/resolve-aliases branch from d7e4fb6 to 0e9ea5a Compare January 7, 2022 20:50
@andyleejordan andyleejordan force-pushed the andschwa/resolve-aliases branch 2 times, most recently from 4194473 to 84ee6b2 Compare January 7, 2022 21:41
s_cmdletToAliasCache.AddOrUpdate(
aliasInfo.Definition,
(_) => new List<string> { aliasInfo.Name},
(_, v) => { v.Add(aliasInfo.Name); return v; });
Copy link
Member

@daxian-dbw daxian-dbw Jan 7, 2022

Choose a reason for hiding this comment

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

This would beat the purpose, as these 2 lambdas are closures and thus new instances will be created for every aliasInfo object, so it will end up with more allocations.

The overload I suggested to use will generate static delegates can are reused for all the calls to AddOrUpdate here, and thus could reduce allocations.

Copy link
Member Author

Choose a reason for hiding this comment

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

The suggested code didn't compile...what's the fix for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see this let me see if I can get it right.

Copy link
Member

Choose a reason for hiding this comment

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

My suggestion is pseudo code :) I didn't try compiling it. I guess the following would work

s_cmdletToAliasCache.AddOrUpdate(
    aliasInfo.Definition,
    (_, arg) => new List<string> { arg },
    (_, v, arg) => { v.Add(arg); return v; },
    aliasInfo.Name);

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm getting this:

No overload for method 'AddOrUpdate' takes 4 arguments

Which is why I made the change I did instead. But I agree the documentation says this overload exists and takes four arguments, and we're using .NET 6 here.

Copy link
Member

Choose a reason for hiding this comment

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

I see, so PSES is targeting netstandard2.0?
In that case, please keep your original code unchanged.

Copy link
Member

Choose a reason for hiding this comment

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

we're using .NET 6 here

Just so I'm clear :) we are using .NET 6 SDK but the build targets netstandard 2.0, is that right?

Copy link
Member Author

Choose a reason for hiding this comment

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

@daxian-dbw Since we're using netstandard2.0 and net461 in order to continue to support Windows PowerShell 5.1, I can't use this overload 😢

Copy link
Member

Choose a reason for hiding this comment

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

That's OK. It's an optimization change anyway 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a TODO to improve this with the better delegate if/when we move to .NET 4.7.2 and/or .NET Standards 2.1 (so really, the day we drop PowerShell 5.1 support).

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM except for the one last comment I left above.

This consolidated the constructors so we don't have some unused (and
confusing) boolean differentiating them, and instead just provide one
constructor with default values. Also clean up `AstOperationsTests`.
Ironically this was clearly how it used to work, and was for some reason
changed, even though it does need to be a task and was previously
relying on synchronous side effects.
Which is where it might be accessed concurrently as a cache, but we can
use `IDictionary` (and return a copy of the caches) to the rest of the
users.
@andyleejordan andyleejordan force-pushed the andschwa/resolve-aliases branch from 84ee6b2 to 627e915 Compare January 8, 2022 01:22
@andyleejordan
Copy link
Member Author

Thanks for your time reviewing @daxian-dbw! This resolves the last disabled test from the original set of Language Server tests.

@andyleejordan andyleejordan merged commit 9aa300b into master Jan 8, 2022
@andyleejordan andyleejordan deleted the andschwa/resolve-aliases branch January 8, 2022 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants