Skip to content

Commit

Permalink
Merge pull request #574 from MarkMpn/intellisense-comments
Browse files Browse the repository at this point in the history
Fixed intellisense with trailing comments
  • Loading branch information
MarkMpn authored Nov 6, 2024
2 parents c61a447 + ff6f01b commit f5cb3cd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions MarkMpn.Sql4Cds.LanguageServer/Autocomplete/Autocomplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,9 @@ private bool InCommentOrStringLiteral(string text, int pos)

while ((i = text.IndexOfAny(new[] { '\n', '-', '\'', '/' }, i + 1)) != -1)
{
if (i > pos)
break;

if (text[i] == '\n')
inSingleLineComment = false;
else if (i > 0 && !inQuotes && text[i - 1] == '-' && text[i] == '-')
Expand Down
12 changes: 12 additions & 0 deletions MarkMpn.Sql4Cds.Tests/AutocompleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,5 +405,17 @@ DECLARE @x varchar

CollectionAssert.IsSubsetOf(new[] { "@i", "@x", "@@ROWCOUNT", "@@IDENTITY", "@@SERVERNAME", "@@VERSION" }, suggestions);
}

[TestMethod]
public void TrailingComment()
{
// https://github.com/MarkMpn/Sql4Cds/issues/569
var prefix = "SELECT * FROM a";
var suffix = "\r\n-- comment";
var sql = prefix + suffix;
var suggestions = _autocomplete.GetSuggestions(sql, prefix.Length - 1).Where(s => s.ImageIndex == 4).Select(s => s.Text).ToList();

CollectionAssert.AreEqual(new[] { "account" }, suggestions);
}
}
}
3 changes: 3 additions & 0 deletions MarkMpn.Sql4Cds.XTB/Autocomplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,9 @@ private bool InCommentOrStringLiteral(string text, int pos)

while ((i = text.IndexOfAny(new[] { '\n', '-', '\'', '/' }, i + 1)) != -1)
{
if (i > pos)
break;

if (text[i] == '\n')
inSingleLineComment = false;
else if (i > 0 && !inQuotes && text[i - 1] == '-' && text[i] == '-')
Expand Down

0 comments on commit f5cb3cd

Please sign in to comment.