From 2afa4b2bd835f1fd2ca0da467bd45dfa150b41b8 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 16 Oct 2019 23:01:42 +0300 Subject: [PATCH] Forwardport 1044 fixing UNC path completions --- .../TextDocument/Handlers/CompletionHandler.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs index 1f2f2e09a..6f4bb6715 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs @@ -5,6 +5,7 @@ using System; using System.Management.Automation; +using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -251,8 +252,13 @@ private static CompletionItem CreateCompletionItem( // This causes the editing cursor to be placed *before* the final quote after completion, // which makes subsequent path completions work. See this part of the LSP spec for details: // https://microsoft.github.io/language-server-protocol/specification#textDocument_completion - int len = completionDetails.CompletionText.Length; - completionText = completionDetails.CompletionText.Insert(len - 1, "$0"); + + // Since we want to use a "tab stop" we need to escape a few things for Textmate to render properly. + var sb = new StringBuilder(completionDetails.CompletionText) + .Replace(@"\", @"\\") + .Replace(@"}", @"\}") + .Replace(@"$", @"\$"); + completionText = sb.Insert(sb.Length - 1, "$0").ToString(); insertTextFormat = InsertTextFormat.Snippet; }