Skip to content

Commit

Permalink
fixes and cleanup
Browse files Browse the repository at this point in the history
- cleanup logging
- add option to control whether intellisense is enabled or not
- ditch some old code.
  • Loading branch information
darrenkopp committed Sep 9, 2013
1 parent 1b701ef commit 6663fbe
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 595 deletions.
4 changes: 0 additions & 4 deletions SassyStudio.2012/Compiler/BackgroundParsingTask.cs
Expand Up @@ -48,8 +48,6 @@ void ProcessRequests()
source.Refresh();
if (source.Exists)
{
Logger.Log(string.Format("Background Parse: {0}", source.FullName));

ISassStylesheet stylesheet = null;
var textManager = new FileTextManager(source);
using (var scope = textManager.Open())
Expand All @@ -60,8 +58,6 @@ void ProcessRequests()

if (stylesheet != null)
request.Document.Update(stylesheet);

Logger.Log(string.Format("Background Parse Complete: {0}", source.FullName));
}
}
catch (Exception ex)
Expand Down
87 changes: 87 additions & 0 deletions SassyStudio.2012/Editor/CommentSelectionCommandHandler.cs
@@ -0,0 +1,87 @@
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using System;
using System.Collections.Generic;

namespace SassyStudio.Editor
{
class CommentSelectionCommandHandler : VSCommandTarget<VSConstants.VSStd2KCmdID>
{
readonly ITextBuffer Buffer;
public CommentSelectionCommandHandler(IVsTextView vsTextView, IWpfTextView textView)
: base(vsTextView, textView)
{
Buffer = textView.TextBuffer;
}

protected override bool Execute(VSConstants.VSStd2KCmdID command, uint options, IntPtr pvaIn, IntPtr pvaOut)
{
if (TextView.Selection.IsEmpty) return false;


var snapshot = Buffer.CurrentSnapshot;
int start = TextView.Selection.Start.Position.Position;
int end = TextView.Selection.End.Position.Position;

// TODO: pre-process the input and determine start position of left-most
// text just like visual studio does

using (var edit = Buffer.CreateEdit())
{
while (start < end)
{
var line = snapshot.GetLineFromPosition(start);
var text = line.GetText();
switch (command)
{
case VSConstants.VSStd2KCmdID.COMMENTBLOCK:
case VSConstants.VSStd2KCmdID.COMMENT_BLOCK:
{
if (!string.IsNullOrEmpty(text))
edit.Insert(line.Start.Position, "//");

break;
}
case VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK:
case VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK:
{
if (text.StartsWith("//", StringComparison.OrdinalIgnoreCase))
edit.Delete(line.Start.Position, 2);

break;
}
}

start = line.EndIncludingLineBreak.Position;
}

edit.Apply();
}

return true;
}

protected override IEnumerable<VSConstants.VSStd2KCmdID> SupportedCommands
{
get
{
yield return VSConstants.VSStd2KCmdID.COMMENTBLOCK;
yield return VSConstants.VSStd2KCmdID.COMMENT_BLOCK;
yield return VSConstants.VSStd2KCmdID.UNCOMMENT_BLOCK;
yield return VSConstants.VSStd2KCmdID.UNCOMMENTBLOCK;
}
}

protected override VSConstants.VSStd2KCmdID ConvertFromCommandId(uint id)
{
return (VSConstants.VSStd2KCmdID)id;
}

protected override uint ConvertFromCommand(VSConstants.VSStd2KCmdID command)
{
return (uint)command;
}
}
}
6 changes: 4 additions & 2 deletions SassyStudio.2012/Editor/DocumentListener.cs
Expand Up @@ -32,8 +32,10 @@ public void VsTextViewCreated(IVsTextView textViewAdapter)
var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
textView.Closed += OnClosed;

// register command handler for completion
textView.Properties.GetOrCreateSingletonProperty(() => new CompletionCommandHandler(CompletionBroker, textViewAdapter, textView));
textView.Properties.GetOrCreateSingletonProperty(() => new CommentSelectionCommandHandler(textViewAdapter, textView));

if (SassyStudioPackage.Instance.Options.Scss.EnableExperimentalIntellisense)
textView.Properties.GetOrCreateSingletonProperty(() => new CompletionCommandHandler(CompletionBroker, textViewAdapter, textView));
}

void OnClosed(object sender, EventArgs e)
Expand Down
Expand Up @@ -16,6 +16,10 @@ public IEnumerable<SassCompletionContextType> GetContext(ParseItem current, int
{
yield return SassCompletionContextType.MixinDirective;
}
else if (current is MixinDefinitionBody)
{
yield return SassCompletionContextType.MixinBody;
}
else if (current is RuleBlock)
{
yield return SassCompletionContextType.IncludeDirective;
Expand All @@ -41,10 +45,6 @@ public IEnumerable<SassCompletionContextType> GetContext(ParseItem current, int

yield return SassCompletionContextType.IncludeDirectiveMixinArgumentValue;
}
else if (current is MixinDefinitionBody)
{
yield return SassCompletionContextType.MixinBody;
}
}
}
}
Expand Up @@ -14,7 +14,6 @@ public IEnumerable<SassCompletionContextType> SupportedContexts
{
get
{
yield return SassCompletionContextType.IncludeDirective;
yield return SassCompletionContextType.IncludeDirectiveMixinName;
}
}
Expand All @@ -23,7 +22,6 @@ public IEnumerable<ICompletionValue> GetCompletions(SassCompletionContextType ty
{
switch (type)
{
case SassCompletionContextType.IncludeDirective:
case SassCompletionContextType.IncludeDirectiveMixinName:
return context.Cache.GetMixins(context.Position);
}
Expand Down
11 changes: 2 additions & 9 deletions SassyStudio.2012/Editor/Intellisense/CompletionCommandHandler.cs
Expand Up @@ -168,12 +168,10 @@ private bool Complete(bool force = false)
// only commit if something selected or forced to commit
if (Session.SelectedCompletionSet.SelectionStatus.IsSelected || force)
{
Logger.Log("Committed.");
Session.Commit();
return true;
}

Logger.Log("dismissed");
// we couldn't commit, so dismiss
Session.Dismiss();
}
Expand All @@ -194,7 +192,6 @@ private bool Dismiss(ICompletionSession session)

private void OnSessionDismissed(object sender, EventArgs e)
{
Logger.Log("Dismissed event.");
var session = sender as ICompletionSession;
session.Dismissed -= OnSessionDismissed;

Expand Down Expand Up @@ -261,8 +258,7 @@ private bool IsTerminalCharacter(char typed)

private int GetCompletionStart(ITextSnapshot snapshot, ITextSnapshotLine line, int position)
{
Logger.Log(string.Format("Scanning for word boundary. Line = '{0}', Position = '{1}'", line.LineNumber, position));
int start = position--;
int start = position;
while (start > line.Start.Position)
{
// stop once we hit whitespace
Expand All @@ -273,10 +269,7 @@ private int GetCompletionStart(ITextSnapshot snapshot, ITextSnapshotLine line, i
}
}

start = Math.Max(start, line.Start.Position);

Logger.Log(string.Format("Start of completion set to {0}", start));
return start;
return Math.Max(start, line.Start.Position);
}

private bool Ignore(VSCommand command, char typed)
Expand Down
6 changes: 5 additions & 1 deletion SassyStudio.2012/Editor/Intellisense/SassCompletionSource.cs
Expand Up @@ -81,7 +81,11 @@ private IEnumerable<SassCompletionContextType> CalculateApplicableContexts(IComp

private ICompletionContext CreateCompletionContext(ISassStylesheet stylesheet, int position)
{
var current = stylesheet.Children.FindItemContainingPosition(position) ?? (stylesheet as Stylesheet);
var current = stylesheet.Children.FindItemContainingPosition(Math.Max(0, position-1));
if (current != null && !current.IsUnclosed)
current = stylesheet.Children.FindItemContainingPosition(position);

current = current ?? (stylesheet as Stylesheet);

return new CompletionContext
{
Expand Down
5 changes: 5 additions & 0 deletions SassyStudio.2012/Options/ScssOptions.cs
Expand Up @@ -46,5 +46,10 @@ public override void LoadSettingsFromStorage()
[Description("When enabled, comments will be added to the .css file specifying the file and line number where the values originated from.")]
[Category("SCSS")]
public bool IncludeSourceComments { get; set; }

[LocDisplayName("Experimental Intellisense")]
[Description("When enabled, statement completion will be enabled for variables, functions, mixins and keywords.")]
[Category("Intellisense")]
public bool EnableExperimentalIntellisense { get; set; }
}
}
7 changes: 1 addition & 6 deletions SassyStudio.2012/SassyStudio.2012.csproj
Expand Up @@ -60,6 +60,7 @@
<Compile Include="Editor\BufferSnapshotChangedCancellationToken.cs" />
<Compile Include="Editor\Classification\SassClassifier.cs" />
<Compile Include="Editor\Classification\SassClassifierProvider.cs" />
<Compile Include="Editor\CommentSelectionCommandHandler.cs" />
<Compile Include="Editor\DocumentListener.cs" />
<Compile Include="Editor\Intellisense\CompletionCommandHandler.cs" />
<Compile Include="Editor\Intellisense\CompletionCompiler.cs" />
Expand Down Expand Up @@ -117,7 +118,6 @@
<Compile Include="Scss\Classifications\ScssClassifier.cs" />
<Compile Include="Scss\Classifications\ScssClassifierProvider.cs" />
<Compile Include="Commands\CommandTargetBase.cs" />
<Compile Include="Scss\Commands\CommentSelection.cs" />
<Compile Include="Scss\GenerateCssOnSave.cs" />
<Compile Include="Scss\ScssContentTypeDefinition.cs" />
<Compile Include="Scss\Classifications\ScssClassificationTypes.cs" />
Expand All @@ -134,11 +134,6 @@
<Compile Include="Scss\Classifications\FormatDefinitions\ScssUserFunctionReference.cs" />
<Compile Include="Scss\Classifications\FormatDefinitions\ScssVariableDefinition.cs" />
<Compile Include="Scss\Classifications\FormatDefinitions\ScssVariableReference.cs" />
<Compile Include="Scss\ScssViewCreationListener.cs" />
<Compile Include="Scss\Taggers\DeprecatedFunctionalityTagger.cs" />
<Compile Include="Scss\Taggers\MultilineTagger.cs" />
<Compile Include="Scss\Taggers\ScssOutliningTagger.cs" />
<Compile Include="Scss\Taggers\ScssOutliningTaggingProvider.cs" />
<Compile Include="Scss\ScssWellKnownFunctionNames.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources.Designer.cs">
Expand Down
74 changes: 0 additions & 74 deletions SassyStudio.2012/Scss/Commands/CommentSelection.cs

This file was deleted.

29 changes: 0 additions & 29 deletions SassyStudio.2012/Scss/ScssViewCreationListener.cs

This file was deleted.

0 comments on commit 6663fbe

Please sign in to comment.