From dab15d7d21fd31cd2f3f38fcce3cec7cbd8e6f3d Mon Sep 17 00:00:00 2001 From: Mads Kristensen Date: Mon, 3 Jan 2022 14:14:20 -0800 Subject: [PATCH] Fixed property parsing and IntelliSense [release] --- src/Language/IntelliSense.cs | 9 ++++++++- src/Language/LanguageFactory.cs | 1 + src/Parser/DocumentParser.cs | 2 +- src/PkgdefPackage.cs | 2 +- test/ParseTest.cs | 17 +++++++++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Language/IntelliSense.cs b/src/Language/IntelliSense.cs index 77f1f89..8671cf4 100644 --- a/src/Language/IntelliSense.cs +++ b/src/Language/IntelliSense.cs @@ -95,7 +95,7 @@ public Task GetDescriptionAsync(IAsyncCompletionSession session, Complet public CompletionStartData InitializeCompletion(CompletionTrigger trigger, SnapshotPoint triggerLocation, CancellationToken token) { - if (trigger.Character == '\n' || trigger.Reason == CompletionTriggerReason.Deletion) + if (trigger.Character == '\n' || trigger.Character == ']' || trigger.Reason == CompletionTriggerReason.Deletion) { return CompletionStartData.DoesNotParticipateInCompletion; } @@ -111,12 +111,19 @@ public CompletionStartData InitializeCompletion(CompletionTrigger trigger, Snaps else if (item?.Type == ItemType.RegistryKey && item.Text.IndexOf("$rootkey$", StringComparison.OrdinalIgnoreCase) > -1) { var column = triggerLocation.Position - item.Span.Start; + + if (column < 1) + { + return CompletionStartData.DoesNotParticipateInCompletion; ; + } + var start = item.Text.LastIndexOf('\\', column - 1) + 1; var end = item.Text.IndexOf('\\', column); var close = item.Text.IndexOf(']', column); var textEnd = item.Text.IndexOf(']', column); end = end >= start ? end : close; end = end >= start ? end : textEnd; + end = end >= start ? end : item.Text.TrimEnd().Length; if (end >= start) { diff --git a/src/Language/LanguageFactory.cs b/src/Language/LanguageFactory.cs index 446d515..296eb24 100644 --- a/src/Language/LanguageFactory.cs +++ b/src/Language/LanguageFactory.cs @@ -38,6 +38,7 @@ public override void SetDefaultPreferences(LanguagePreferences preferences) preferences.WordWrapGlyphs = true; preferences.AutoListMembers = true; + preferences.HideAdvancedMembers = false; preferences.EnableQuickInfo = true; preferences.ParameterInformation = true; } diff --git a/src/Parser/DocumentParser.cs b/src/Parser/DocumentParser.cs index b091e3e..f167527 100644 --- a/src/Parser/DocumentParser.cs +++ b/src/Parser/DocumentParser.cs @@ -6,7 +6,7 @@ namespace PkgdefLanguage { public partial class Document { - private static readonly Regex _regexProperty = new(@"^(?.+)(\s)*(?=)\s*(?.+)", RegexOptions.Compiled); + private static readonly Regex _regexProperty = new(@"^(?.+)(\s)*(?=)\s*(?(dword:[\d].+|"".+))", RegexOptions.Compiled); private static readonly Regex _regexRef = new(@"\$[\w]+\$?", RegexOptions.Compiled); public void Parse() diff --git a/src/PkgdefPackage.cs b/src/PkgdefPackage.cs index e40b5ee..4b84e82 100644 --- a/src/PkgdefPackage.cs +++ b/src/PkgdefPackage.cs @@ -14,7 +14,7 @@ namespace PkgdefLanguage [Guid(PackageGuids.PkgdefLanguageString)] [ProvideMenuResource("Menus.ctmenu", 1)] - [ProvideLanguageService(typeof(LanguageFactory), Constants.LanguageName, 0, DefaultToInsertSpaces = true, EnableLineNumbers = true, MatchBraces = true, MatchBracesAtCaret = true, EnableAsyncCompletion = true, EnableCommenting = true, ShowCompletion = true, ShowMatchingBrace = true)] + [ProvideLanguageService(typeof(LanguageFactory), Constants.LanguageName, 0, DefaultToInsertSpaces = true, EnableLineNumbers = true, MatchBraces = true, MatchBracesAtCaret = true, EnableAsyncCompletion = true, EnableCommenting = true, ShowCompletion = true, ShowMatchingBrace = true, HideAdvancedMembersByDefault = false)] [ProvideLanguageExtension(typeof(LanguageFactory), Constants.PkgDefExt)] [ProvideLanguageExtension(typeof(LanguageFactory), Constants.PkgUndefExt)] [ProvideFileIcon(Constants.PkgDefExt, "KnownMonikers.RegistrationScript")] diff --git a/test/ParseTest.cs b/test/ParseTest.cs index 23fb4a8..5887cce 100644 --- a/test/ParseTest.cs +++ b/test/ParseTest.cs @@ -28,6 +28,23 @@ public async Task SingleEntry() Assert.AreEqual(16, entry.Span.End); } + [TestMethod] + public async Task EqualsInPropertyValue() + { + var lines = new[] { "[test]\r\n", + "@=\"test=1234\"" + }; + + var doc = Document.FromLines(lines); + await doc.WaitForParsingCompleteAsync(); + var entries = doc.Items.OfType().ToList(); + + Assert.AreEqual(1, entries.Count); + + Entry entry = entries.First(); + Assert.AreEqual("\"test=1234\"", entry.Properties.First().Value.Text); + } + [TestMethod] public async Task MultipleEntries() {