question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

completions for attribute/type alias's inconsistent.

See original GitHub issue

System Details

  • Operating system name and version: Win 10 1809
  • VS Code version: 1.33.1 (user)
  • PowerShell extension version: 2.0.2
  • PowerShell: 6.2.0

Issue Description

try: Enter [PSDefaultValue], note the completion suggestion PSDefaultValueAttribute, accept the completion, the value inserted is PSDefaultValue. This is good. Enter [Flags], note the completion suggestion FlagsAttribute, accept the completion, the value actually inserted is System.FlagsAttribute. I expected just Flags. Similar result for [Ordered]. EDIT: [PSCustomObject] offers PSObject and a snippet for ‘PSCustomObject’. Accepting the PSObject actually inserts pscustomobject which is kind of confusing.

Why the difference between the completions for these objects?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
rjmholtcommented, May 2, 2019

@SeeminglyScience has already covered all the important points here, but to summarise:

  • PowerShell has a pretty obvious algorithm for resolving/completing type names in the [...] syntax
  • But this is complicated by two fallback rules when immediate type resolution fails:
    • It prepends System. implicitly and looks again (notice that [object] isn’t a type accelerator)
    • When the [...()] attribute syntax is used, it will also append Attribute and look again
  • Then there are type accelerators (like [psmoduleinfo] or [semver]), although a lot of these would already work with the implicit System. (like [uri], [version] and [char])
  • Then there are some things that are essentially pseudo type accelerators, which may or may not reference a type (e.g. [ordered] doesn’t but [psobject] does) but have specific semantic meaning. [ref] is an interesting case here because it looks like a cast, but is used more like an attribute in C# (it works fine as a type accelerator though).

These make life hard because the completion API has the naive assumption that type accelerators can be uniquely represented by their type name, but:

  • [psobject] and [pscustomobject] both point to the same type (even though they do different things)
  • [ordered] points to no type at all (it’s not actually a type accelerator even though it’s perfectly suited to be one), so you don’t even get a completion for it (even in the PowerShell console)!
0reactions
SeeminglySciencecommented, May 1, 2019

When PowerShell expects that the type should resolve to an Attribute, it will append Attribute to the type name if resolution fails without it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

16.20 - 6842 Attribute type cannot be the type under creation or ...
2554 Inconsistent situation occurs in restart MLoad - %VSTR ... 3868 A table or view without alias appears more than once in FROM...
Read more >
Web service error codes (Microsoft Dataverse) - Power Apps
Fix this inconsistency, and then import this data map again. 0x80040390 ... Field is not supported for MultiSelectPicklist Attribute Type.
Read more >
DS 5 > Log Message Reference - ForgeRock Backstage
Message: An error occurred while trying to parse the completion time value %s ... Message: Unable to remove attribute type %s from the...
Read more >
LDAP: The Protocol - IETF
Upon completion of the operation(s), the server returns a response ... Briefly, an attribute description is an attribute type and zero or more...
Read more >
XSL Transformations (XSLT) Version 2.0 (Second Edition)
On completion of the xsl:apply-templates instruction, ... [Definition: A stylesheet can use the xsl:namespace-alias element to declare that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found