Skip to content

Commit

Permalink
Fixed property parsing and IntelliSense
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
madskristensen committed Jan 3, 2022
1 parent 5f85d2d commit dab15d7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Language/IntelliSense.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Task<object> 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;
}
Expand All @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/Language/LanguageFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/DocumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PkgdefLanguage
{
public partial class Document
{
private static readonly Regex _regexProperty = new(@"^(?<name>.+)(\s)*(?<equals>=)\s*(?<value>.+)", RegexOptions.Compiled);
private static readonly Regex _regexProperty = new(@"^(?<name>.+)(\s)*(?<equals>=)\s*(?<value>(dword:[\d].+|"".+))", RegexOptions.Compiled);
private static readonly Regex _regexRef = new(@"\$[\w]+\$?", RegexOptions.Compiled);

public void Parse()
Expand Down
2 changes: 1 addition & 1 deletion src/PkgdefPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
17 changes: 17 additions & 0 deletions test/ParseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entry>().ToList();

Assert.AreEqual(1, entries.Count);

Entry entry = entries.First();
Assert.AreEqual("\"test=1234\"", entry.Properties.First().Value.Text);
}

[TestMethod]
public async Task MultipleEntries()
{
Expand Down

0 comments on commit dab15d7

Please sign in to comment.