Skip to content

Untitled and in-memory PowerShell files should have language features enabled #44

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

Closed
daviwil opened this issue Nov 18, 2015 · 6 comments

Comments

@daviwil
Copy link
Contributor

daviwil commented Nov 18, 2015

A user reported a crash of the language service with the following log output:

11/18/2015 11:09:48 AM [VERBOSE] - Method "ReadMessage" at line 111 of c:\projects\powershelleditorservices\src\PowerShellEditorServices.Protocol\MessageProtocol\MessageReader.cs

    READ MESSAGE:

    {
      "jsonrpc": "2.0",
      "method": "textDocument/didOpen",
      "params": {
        "uri": "inmemory://model/3",
        "text": " ... file contents ..."
      }
    }

11/18/2015 11:09:48 AM [VERBOSE] - Method "ResolveFilePath" at line 197 of c:\projects\powershelleditorservices\src\PowerShellEditorServices\Workspace\Workspace.cs

    Resolved path: inmemory:\\model\3

11/18/2015 11:09:48 AM [ERROR] - Method "CurrentDomain_UnhandledException" at line 79 of c:\projects\powershelleditorservices\src\PowerShellEditorServices.Host\Program.cs

    FATAL UNHANDLED EXCEPTION:

    System.NotSupportedException: The given path's format is not supported.
       at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
       at Microsoft.PowerShell.EditorServices.Workspace.ResolveFilePath(String filePath)
       at Microsoft.PowerShell.EditorServices.Workspace.GetFileBuffer(String filePath, String initialBuffer)
       at Microsoft.PowerShell.EditorServices.Host.LanguageServer.HandleDidOpenTextDocumentNotification(DidOpenTextDocumentNotification openParams, EditorSession editorSession, EventContext eventContext)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher`1.<>c__DisplayClass4`1.<AddEventHandler>b__3(Message eventMessage, TSession session, MessageWriter messageWriter)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher`1.<DispatchMessage>d__6.MoveNext()

It appears that VS Code sent an invalid file path to the language service: inmemory://model/3. Not sure what would cause it to send this path but the language service should be able to gracefully reject invalid file paths.

@adamdriscoll
Copy link
Contributor

Sounds like an unsaved file. I thought that wasn't possible yet?

@daviwil
Copy link
Contributor Author

daviwil commented Nov 18, 2015

Actually... maybe it is. This weekend I converted to a new JSON protocol which gives responsibility to the client for sending file contents to the server (even if the file exists on disk). Maybe this is the first case where VS Code tried to send me an untitled file?

@adamdriscoll
Copy link
Contributor

Seems like it! But I have no idea how to even make Code aware of the language type without saving it...

@adamdriscoll
Copy link
Contributor

Actually, found it.

In VS Code, we default the language support for a file based on its filename extension. However at times you may wish to change language modes, to do this click on the language indicator - which is located on the right hand of the status bar. This will bring up the Command Palette for Select Language Mode.

@adamdriscoll
Copy link
Contributor

And changing the language on an unsaved file after switching it to PowerShell crashes the host process. :D

@daviwil
Copy link
Contributor Author

daviwil commented Nov 18, 2015

Sounds like I need to fix that ;)

@daviwil daviwil changed the title Catch NotSupportedException when parsing file paths with System.Uri Untitled and in-memory PowerShell files should have language features enabled Nov 20, 2015
TylerLeonhardt pushed a commit to TylerLeonhardt/PowerShellEditorServices that referenced this issue Feb 26, 2019
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

No branches or pull requests

2 participants