Skip to content

Commit

Permalink
fix parsing and intellisense
Browse files Browse the repository at this point in the history
i'm rusty
  • Loading branch information
darrenkopp committed Sep 7, 2013
1 parent bba786d commit 1b701ef
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 5 deletions.
6 changes: 5 additions & 1 deletion SassyStudio.2012/Editor/Classification/SassClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)

var type = ClassifierContextCache.Get(current.ClassifierType).GetClassification(Registry);
if (type != null)
results.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(current.Start, current.Length)), type));
{
var start = Math.Max(0, current.Start);
var length = Math.Min(snapshot.Length - start, current.Length);
results.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(start, length)), type));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SassyStudio.Compiler.Parsing;
using SassyStudio.Compiler.Parsing.Rules;

namespace SassyStudio.Editor.Intellisense
{
[Export(typeof(ICompletionContextProvider))]
class KeyframesContextProvider : ICompletionContextProvider
{
public IEnumerable<SassCompletionContextType> GetContext(ParseItem current, int position)
{
if (current is Stylesheet)
yield return SassCompletionContextType.KeyframesDirective;

if (current is KeyframeRuleBlock)
yield return SassCompletionContextType.KeyframesNamedRange;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public IEnumerable<SassCompletionContextType> SupportedContexts
yield return SassCompletionContextType.FunctionDirective;
yield return SassCompletionContextType.ImportDirective;
yield return SassCompletionContextType.IncludeDirective;
yield return SassCompletionContextType.KeyframesDirective;
yield return SassCompletionContextType.KeyframesNamedRange;
yield return SassCompletionContextType.MixinDirective;
yield return SassCompletionContextType.VariableDefaultFlag;
yield return SassCompletionContextType.WhileLoopDirective;
Expand Down Expand Up @@ -84,6 +86,13 @@ IEnumerable<string> GetKeywords(SassCompletionContextType type)
case SassCompletionContextType.IncludeDirective:
yield return "@include";
break;
case SassCompletionContextType.KeyframesDirective:
yield return "@keyframes";
break;
case SassCompletionContextType.KeyframesNamedRange:
yield return "from";
yield return "to";
break;
case SassCompletionContextType.MixinDirective:
yield return "@mixin";
break;
Expand Down
1 change: 1 addition & 0 deletions SassyStudio.2012/SassyStudio.2012.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="Editor\Intellisense\Completion\BlockScopeContainer.cs" />
<Compile Include="Editor\Intellisense\Completion\CompletionContainerBase.cs" />
<Compile Include="Editor\Intellisense\Completion\ContextProviders\ImportingContextProvider.cs" />
<Compile Include="Editor\Intellisense\Completion\ContextProviders\KeyframesContextProvider.cs" />
<Compile Include="Editor\Intellisense\Completion\ContextProviders\PropertyContextProvider.cs" />
<Compile Include="Editor\Intellisense\Completion\FunctionContainer.cs" />
<Compile Include="Editor\Intellisense\Completion\ImportContainer.cs" />
Expand Down
8 changes: 4 additions & 4 deletions SassyStudio.Compiler/Parsing/Rules/KeyframeSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public override bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenS
}
else if (stream.Current.Type == TokenType.Number && stream.Peek(1).Type == TokenType.PercentSign)
{
ParseItem begin;
if (itemFactory.TryCreateParsed<PercentageUnit>(this, text, stream, out begin))
ParseItem begin = itemFactory.Create<PercentageUnit>(this, text, stream);
if (begin.Parse(itemFactory, text, stream))
{
AnimationBegin = begin;
Children.Add(begin);

if (stream.Current.Type == TokenType.Comma)
Comma = Children.AddCurrentAndAdvance(stream, SassClassifierType.Punctuation);

ParseItem end;
if (itemFactory.TryCreateParsed<PercentageUnit>(this, text, stream, out end))
ParseItem end = itemFactory.Create<PercentageUnit>(this, text, stream);
if (end.Parse(itemFactory, text, stream))
{
AnimationEnd = end;
Children.Add(end);
Expand Down
1 change: 1 addition & 0 deletions SassyStudio.Interfaces/Compiler/Parsing/ParseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public abstract class ParseItem : IRange
public abstract int End { get; }
public abstract int Length { get; }
public virtual bool IsValid { get { return true; } }
public virtual bool IsUnclosed { get { return false; } }

public abstract bool Parse(IItemFactory itemFactory, ITextProvider text, ITokenStream stream);
public virtual void Freeze()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public enum SassCompletionContextType
ImportDirective,
ImportDirectiveFile,

KeyframesDirective,
KeyframesNamedRange,

StringInterpolation,
StringInterpolationValue,

Expand Down

0 comments on commit 1b701ef

Please sign in to comment.