mirror of
https://github.com/OlivierGuinart/Merlin32Language.git
synced 2025-01-02 20:29:45 +00:00
Fix to prevent autocompletion in comments + small refactoring
This commit is contained in:
parent
d821e25fdb
commit
a7a3708a53
@ -9,14 +9,9 @@ namespace VSMerlin32.Coloring
|
||||
internal class Merlin32CodeHelper
|
||||
{
|
||||
const string COMMENT_REG = @"((\u003B)|(\u002A))(.*)"; // ;
|
||||
//const string KEYLINE_REG = @"\u0023([\w]*)"; // #
|
||||
//const string HEAD_REG = @"^(\w)+(.*)\u003a\u002d"; // :-
|
||||
const string TEXT_REG = @"(""|')[^']*(""|')";
|
||||
//const string PUBLIC_REG = @"^\u003a\u002d+(.)*";
|
||||
// const string OPCODE_REG = @"(org)|(ldy)";
|
||||
// OPCODE_REG is initialized dynamically below.
|
||||
static string OPCODE_REG = "";
|
||||
//const string TEXT2_REG = @"\$[^']*\$";
|
||||
static string DIRECTIVE_REG = "";
|
||||
static string DATADEFINE_REG = "";
|
||||
|
||||
@ -35,25 +30,6 @@ namespace VSMerlin32.Coloring
|
||||
yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, match.Index + curLoc), match.Length), Merlin32TokenTypes.Merlin32Comment);
|
||||
}
|
||||
|
||||
/*
|
||||
reg = new Regex(KEYLINE_REG);
|
||||
foreach (Match match in reg.Matches(formattedLine))
|
||||
{
|
||||
if (match.Index < commentMatch)
|
||||
yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, match.Index + curLoc), match.Length), Merlin32TokenTypes.Merlin32Keyline);
|
||||
}
|
||||
|
||||
reg = new Regex(HEAD_REG);
|
||||
foreach (Match match in reg.Matches(formattedLine))
|
||||
{
|
||||
if (match.Index < commentMatch)
|
||||
{
|
||||
int length = formattedLine.IndexOf("(");
|
||||
yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, match.Index + curLoc), length != -1 ? length : match.Length), Merlin32TokenTypes.Merlin32Keyline);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
reg = new Regex(TEXT_REG);
|
||||
foreach (Match match in reg.Matches(formattedLine))
|
||||
{
|
||||
@ -87,9 +63,6 @@ namespace VSMerlin32.Coloring
|
||||
if (token.ToString() != Resources.directives.ELUP)
|
||||
strTempRegex += (token.ToString() + ("|"));
|
||||
}
|
||||
// we remove the last "|" added
|
||||
// strTempRegex = strTempRegex.Remove(strTempRegex.LastIndexOf("|"));
|
||||
// DIRECTIVE_REG = string.Format(@"\b({0})\b", strTempRegex);
|
||||
DIRECTIVE_REG = string.Format(@"\b({0})\b|{1}", strTempRegex, Resources.directives.ELUPRegex);
|
||||
|
||||
reg = new Regex(DIRECTIVE_REG, RegexOptions.IgnoreCase);
|
||||
@ -116,15 +89,6 @@ namespace VSMerlin32.Coloring
|
||||
if (match.Index < commentMatch)
|
||||
yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, match.Index + curLoc), match.Length), Merlin32TokenTypes.Merlin32DataDefine);
|
||||
}
|
||||
|
||||
/*
|
||||
reg = new Regex(PUBLIC_REG);
|
||||
foreach (Match match in reg.Matches(formattedLine))
|
||||
{
|
||||
if (match.Index < commentMatch)
|
||||
yield return new SnapshotHelper(new SnapshotSpan(new SnapshotPoint(span.Snapshot, match.Index + curLoc), match.Length), Merlin32TokenTypes.Merlin32Publictoken);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ namespace VSMerlin32
|
||||
m_session.Commit();
|
||||
this.m_textView.Caret.MoveTo(CaretBeforeCommit.Position.BufferPosition - 1);
|
||||
}
|
||||
else
|
||||
else if (!m_session.IsDismissed)
|
||||
{
|
||||
m_session.Filter();
|
||||
}
|
||||
@ -158,9 +158,28 @@ namespace VSMerlin32
|
||||
caretPoint.Value.Snapshot.CreateTrackingPoint(caretPoint.Value.Position, PointTrackingMode.Positive),
|
||||
true);
|
||||
|
||||
//subscribe to the Dismissed event on the session
|
||||
m_session.Dismissed += this.OnSessionDismissed;
|
||||
m_session.Start();
|
||||
// We need to check now whether we are in a comment or not, because if we are, we don't want to provide a completion list to the user
|
||||
ITextSnapshot snapshot = caretPoint.Value.Snapshot;
|
||||
var triggerPoint = (SnapshotPoint)m_session.GetTriggerPoint(snapshot);
|
||||
var snapshotSpan = new SnapshotSpan(triggerPoint, 0);
|
||||
foreach (VSMerlin32.Coloring.Data.SnapshotHelper item in VSMerlin32.Coloring.Merlin32CodeHelper.GetTokens(snapshotSpan))
|
||||
{
|
||||
if (item.Snapshot.IntersectsWith(snapshotSpan))
|
||||
{
|
||||
if (item.TokenType == Merlin32TokenTypes.Merlin32Comment)
|
||||
{
|
||||
m_session.Dismiss();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_session.IsDismissed)
|
||||
{
|
||||
//subscribe to the Dismissed event on the session
|
||||
m_session.Dismissed += this.OnSessionDismissed;
|
||||
m_session.Start();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -52,49 +52,24 @@ namespace VSMerlin32
|
||||
else
|
||||
{
|
||||
// If the user has been typing lowercase, we'll present a lowercase list of keywords/opcodes...
|
||||
if (char.IsLower(chTyped))
|
||||
foreach (Merlin32Opcodes token in Enum.GetValues(typeof(Merlin32Opcodes)))
|
||||
{
|
||||
foreach (Merlin32Opcodes token in Enum.GetValues(typeof(Merlin32Opcodes)))
|
||||
strList.Add(char.IsLower(chTyped)? token.ToString().ToLower() : token.ToString());
|
||||
}
|
||||
foreach (Merlin32Directives token in Enum.GetValues(typeof(Merlin32Directives)))
|
||||
{
|
||||
if ((token.ToString().ToLower() == Merlin32Directives.ELUP.ToString().ToLower()) || (token.ToString() == Merlin32Directives.ELUP.ToString()))
|
||||
{
|
||||
strList.Add(token.ToString().ToLower());
|
||||
strList.Add(Resources.directives.ELUPValue);
|
||||
}
|
||||
foreach (Merlin32Directives token in Enum.GetValues(typeof(Merlin32Directives)))
|
||||
else
|
||||
{
|
||||
if (token.ToString().ToLower() == Merlin32Directives.ELUP.ToString().ToLower())
|
||||
{
|
||||
strList.Add(Resources.directives.ELUPValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
strList.Add(token.ToString().ToLower());
|
||||
}
|
||||
}
|
||||
foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines)))
|
||||
{
|
||||
strList.Add(token.ToString().ToLower());
|
||||
strList.Add(char.IsLower(chTyped)? token.ToString().ToLower() : token.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines)))
|
||||
{
|
||||
foreach (Merlin32Opcodes token in Enum.GetValues(typeof(Merlin32Opcodes)))
|
||||
{
|
||||
strList.Add(token.ToString());
|
||||
}
|
||||
foreach (Merlin32Directives token in Enum.GetValues(typeof(Merlin32Directives)))
|
||||
{
|
||||
if (token.ToString() == Merlin32Directives.ELUP.ToString())
|
||||
{
|
||||
strList.Add(Resources.directives.ELUPValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
strList.Add(token.ToString());
|
||||
}
|
||||
}
|
||||
foreach (Merlin32DataDefines token in Enum.GetValues(typeof(Merlin32DataDefines)))
|
||||
{
|
||||
strList.Add(token.ToString());
|
||||
}
|
||||
strList.Add(char.IsLower(chTyped)? token.ToString().ToLower() : token.ToString());
|
||||
}
|
||||
|
||||
// OG We also need to replace "ELUP" with "--^"
|
||||
@ -106,23 +81,6 @@ namespace VSMerlin32
|
||||
m_compList = new List<Completion>();
|
||||
foreach (string str in strList)
|
||||
m_compList.Add(new Completion(str, str, str, null, null));
|
||||
/*
|
||||
ITextSnapshot snapshot = _buffer.CurrentSnapshot;
|
||||
var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot);
|
||||
|
||||
if (triggerPoint == null)
|
||||
return;
|
||||
|
||||
var line = triggerPoint.GetContainingLine();
|
||||
SnapshotPoint start = triggerPoint;
|
||||
|
||||
while (start > line.Start && !char.IsWhiteSpace((start - 1).GetChar()))
|
||||
{
|
||||
start -= 1;
|
||||
}
|
||||
|
||||
var applicableTo = snapshot.CreateTrackingSpan(new SnapshotSpan(start, triggerPoint), SpanTrackingMode.EdgeInclusive);
|
||||
*/
|
||||
|
||||
completionSets.Add(new CompletionSet("All", "All", FindTokenSpanAtPosition(session.GetTriggerPoint(m_buffer), session), m_compList, null));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user