From 79559ab5499bace4a5bf66e9a5f1b105b567231e Mon Sep 17 00:00:00 2001 From: NeilMacMullen Date: Fri, 12 Feb 2021 10:17:22 +0000 Subject: [PATCH 01/55] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c45d08b..7272a3c 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ The current release is **v1.3.0**. ## What's new ### vNext (source only) +- **Note - code completion is known to be broken in the current source build** - Update to Monaco 22.3 which supports an extra couple of languages - Rewire font-size control, line numbers, wordwarp to model/output panes - remove minimap from model/output panes From d5e5205cbe57015ef96eead85e14e984c83ee47a Mon Sep 17 00:00:00 2001 From: NeilMacMullen Date: Fri, 12 Feb 2021 10:18:19 +0000 Subject: [PATCH 02/55] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7272a3c..1fc3d1e 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ The current release is **v1.3.0**. ## What's new ### vNext (source only) -- **Note - code completion is known to be broken in the current source build** +- **Note - template intellisense/code-completion is known to be broken in the current source build** - Update to Monaco 22.3 which supports an extra couple of languages - Rewire font-size control, line numbers, wordwarp to model/output panes - remove minimap from model/output panes From ab37fe8636a314a80fe597704c11cddb1d0664c6 Mon Sep 17 00:00:00 2001 From: NeilMacMullen Date: Sat, 13 Feb 2021 10:07:02 +0000 Subject: [PATCH 03/55] Proof of concept --- .../Monaco/Messages/UpdateCompletions.cs | 12 ++++ .../Monaco/Messages/UpdateLanguage.cs | 5 ++ TextrudeInteractive/Monaco/MonacoBinding.cs | 16 +++-- TextrudeInteractive/Resources/monaco.html | 67 ++++++++++++++++++- .../TextrudeInteractive.csproj | 5 ++ 5 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 TextrudeInteractive/Monaco/Messages/UpdateCompletions.cs diff --git a/TextrudeInteractive/Monaco/Messages/UpdateCompletions.cs b/TextrudeInteractive/Monaco/Messages/UpdateCompletions.cs new file mode 100644 index 0000000..b401111 --- /dev/null +++ b/TextrudeInteractive/Monaco/Messages/UpdateCompletions.cs @@ -0,0 +1,12 @@ +namespace TextrudeInteractive.Monaco.Messages +{ + /// + /// Sent TO Monaco tell it to change syntax highlighting + /// + public record UpdateCompletions : MonacoMessages + { + public UpdateCompletions(Completions c) => Completions = c; + + public Completions Completions { get; } + } +} diff --git a/TextrudeInteractive/Monaco/Messages/UpdateLanguage.cs b/TextrudeInteractive/Monaco/Messages/UpdateLanguage.cs index c680360..2ba19be 100644 --- a/TextrudeInteractive/Monaco/Messages/UpdateLanguage.cs +++ b/TextrudeInteractive/Monaco/Messages/UpdateLanguage.cs @@ -11,4 +11,9 @@ public record UpdateLanguage : MonacoMessages public string Language { get; } } + + + public record CompletionNode(string name, string description); + + public record Completions(CompletionNode[] helpers); } diff --git a/TextrudeInteractive/Monaco/MonacoBinding.cs b/TextrudeInteractive/Monaco/MonacoBinding.cs index d917061..adb519a 100644 --- a/TextrudeInteractive/Monaco/MonacoBinding.cs +++ b/TextrudeInteractive/Monaco/MonacoBinding.cs @@ -164,6 +164,16 @@ private static string ContentResponse(Stream content, string mimeType) public void SetTextSize(double textSize) { PostMessage(new FontSize(textSize)); + + var msg = new UpdateCompletions( + new Completions( + new[] + { + new CompletionNode($"abcd {textSize}", "def"), + new CompletionNode($"hhhh {textSize}", "xyz"), + })); + var json = JsonSerializer.Serialize(msg, new JsonSerializerOptions {WriteIndented = true}); + PostMessage(msg); } public void SetLineNumbers(bool onOff) @@ -176,12 +186,6 @@ public void SetWordWrap(bool onOff) PostMessage(new WordWrap(onOff)); } - public void SetViewOptions(double textSize, bool lineNumbersOn, bool wordWrapOn) - { - SetTextSize(textSize); - SetLineNumbers(lineNumbersOn); - SetWordWrap(wordWrapOn); - } public void Setup(string format, bool onOff) { diff --git a/TextrudeInteractive/Resources/monaco.html b/TextrudeInteractive/Resources/monaco.html index 699a7ff..98c1923 100644 --- a/TextrudeInteractive/Resources/monaco.html +++ b/TextrudeInteractive/Resources/monaco.html @@ -35,6 +35,27 @@ }); const model = editor.getModel(); var settingText = false; + var completions = { + helpers: [ + { + name: "humanizr.camelcase", + description: "CameCasing" + }, + { + name: "humanizr.pascalcase", + description: "PascalCasing" + }, + { + name: "humanizr.kebaberize", + description: "kebab-like-string" + }, + { + name: "debug", + description: "some more useful stuff" + } + + ] + }; window.addEventListener('resize', (event) => { editor.layout(); @@ -67,7 +88,7 @@ monaco.editor.setModelLanguage(model, event.data.Language); } else if (event.data.Type === "FontSize") { editor.updateOptions({ - fontSize: event.data.Size + fontSize: event.data.Size }); } else if (event.data.Type === "LineNumbers") { editor.updateOptions({ @@ -81,9 +102,53 @@ editor.updateOptions({ renderWhitespace: event.data.WhitespaceType }); + } else if (event.data.Type === "UpdateCompletions") { + completions = event.data.Completions; } }); + + + function ShowAutocompletion(obj) { + + // Register object that will return autocomplete items + monaco.languages.registerCompletionItemProvider('scriban', { + // Run this function when the period or open parenthesis is typed (and anything after a space) + triggerCharacters: ['.', '('], + + // Function to generate autocompletion results + provideCompletionItems: function(model, position, token) { + // Split everything the user has typed on the current line up at each space, and only look at the last word + var last_chars = model.getValueInRange({ startLineNumber: position.lineNumber, startColumn: 0, endLineNumber: position.lineNumber, endColumn: position.column }); + var words = last_chars.replace("\t", "").split(" "); + var active_typing = words[words.length - 1]; // What the user is currently typing (everything after the last space) + + + // Array of autocompletion results + var result = []; + // Create completion object + completions.helpers.forEach(function(item) { + if (item.name.startsWith(active_typing)) { + var to_push = { + label: item.name, + kind: monaco.languages.CompletionItemKind.Property, + detail: item.description, + insertText: item.name + }; + // Add to final results + result.push(to_push); + } + }); + + return { + suggestions: result + }; + } + }); + }; + + ShowAutocompletion(); + //forcing a layout here seems to help with the white flash slightly monaco.editor.setModelLanguage(model, "csharp"); editor.layout(); diff --git a/TextrudeInteractive/TextrudeInteractive.csproj b/TextrudeInteractive/TextrudeInteractive.csproj index ba9707d..e61f62d 100644 --- a/TextrudeInteractive/TextrudeInteractive.csproj +++ b/TextrudeInteractive/TextrudeInteractive.csproj @@ -43,4 +43,9 @@ + + + + + From b203002d77fde6087d47ae91812b89a78be112c3 Mon Sep 17 00:00:00 2001 From: NeilMacMullen Date: Sat, 13 Feb 2021 11:20:47 +0000 Subject: [PATCH 04/55] Use ShowPreview on GridSplitter to make resizing a little less ugly --- TextrudeInteractive/MainWindow.xaml | 1 + 1 file changed, 1 insertion(+) diff --git a/TextrudeInteractive/MainWindow.xaml b/TextrudeInteractive/MainWindow.xaml index 6da6844..4a96cf9 100644 --- a/TextrudeInteractive/MainWindow.xaml +++ b/TextrudeInteractive/MainWindow.xaml @@ -22,6 +22,7 @@