Skip to content

better error protection for language service - #3379

Merged
KevinRansom merged 1 commit into
dotnet:masterfrom
dsyme:fix-461633
Jul 26, 2017
Merged

KevinRansom merged 1 commit into
dotnet:masterfrom
dsyme:fix-461633

Conversation

@dsyme

@dsyme dsyme commented Jul 25, 2017

Copy link
Copy Markdown
Contributor

Some watson dump error reports reported automatically to Microsoft are showing failures where exceptions are escaping the language service. This fix adds error protection to more language service entry points, and adds error recovery for incomplete assembly reference sets in some extra cases.

@dsyme

dsyme commented Jul 25, 2017 •

Copy link
Copy Markdown
Contributor Author
  1. The situation is a missing assembly reference in the user’s project file. This is legitimate but not particularly common. For the most part we handle this situation correctly.

  2. The correct behaviour in this situation is as follows

    • The missing assembly reference causes the compiler to trigger an error when exploring the metadata for that assembly.
    • During command-line compilation, the correct behaviour for the compiler in this situation is to report an error. The user will normally see this error and fix the problem.
    • For the language service intellisense requests, the correct behaviour is to skip over the missing assembly reference when, for example, collecting declarations to show in the IDE. This is done using calls to “protectAssemblyExploration” which can be found already in several places the code
  3. Our methodology to prepare a fix is to do two things:

    • find the first callstack entry that is unique to the language service where it is possible to return a “default” value and to use “protectAssemblyExploration” to do that.

    • find the entrypoint to the language service which is manipulating F# symbols and protect that using ErrorScope.Protect, again returning a default value. This is a catch-all.

  4. The PR resolves this as follows

    • Looking back down the stack, we find suitable places to protection are

      • ResolveCompletionsInType (the first stack frame specific to FCS)
      • GetSymbolUseAtLocation (the entry point to FCS, which, sure enough, was missing this protection).
    • On review, I have also added protection here:

      • IsItemResolvable (new unprotected code added in VS2017 that is specific to FCS and was unprotected and where it is reasonable to return a default value)
      • GetVisibleNamespacesAndModulesAtPoint (new unprotected code added in VS2017 that is specific to FCS where it is reasonable to return a default value)
      • GetMethodsAsSymbols (a new entry point to FCS added in VS2017, though as yet unused by the Visual F# Tools)
      • GetSemanticClassification (a new entry point to FCS added in VS2017, used extensively by colorization in the Visual F# Tools)
  5. The cause is that new code has been brought over from the Visual F# Power Tools which manipulates symbols (and thus does assembly exploration).

  6. Our testing of the language service in the presence of incomplete assembly reference sets is not great – we have some smoke tests but nothing systematic (e.g. where we systematically delete assembly references and re-run existing tests checking only that no exceptions are escaping).

@Pilchie Pilchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @dsyme!

@Pilchie

Pilchie commented Jul 25, 2017

Copy link
Copy Markdown
Member

Tagging @brettfo as this is another candidate for cherry-picking to 15.3.

@KevinRansom
KevinRansom merged commit 938da3e into dotnet:master Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants