Skip to content

Commit

Permalink
VS plugin fixes
Browse files Browse the repository at this point in the history
Show autocomplete even when there are no nested concepts.
This interferes with outlining which now shows + for empty children.
Scan nested projects for dsl files.
  • Loading branch information
zapov committed Oct 29, 2017
1 parent 4b273f1 commit 66c27f1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
6 changes: 6 additions & 0 deletions VisualStudioPlugin/Gui/ServerActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ private static void GatherCurrentDsl(ProjectItems items, Dictionary<string, stri
}
if (pi.ProjectItems != null)
GatherCurrentDsl(pi.ProjectItems, dsls);
var subproject = pi.SubProject;
if (subproject != null && subproject.ProjectItems != null)
GatherCurrentDsl(subproject.ProjectItems, dsls);
}
}

Expand All @@ -211,6 +214,9 @@ private static void LocateCurrentDsl(ProjectItems items, List<string> dsls)
}
if (pi.ProjectItems != null)
LocateCurrentDsl(pi.ProjectItems, dsls);
var subproject = pi.SubProject;
if (subproject != null && subproject.ProjectItems != null)
LocateCurrentDsl(subproject.ProjectItems, dsls);
}
}

Expand Down
22 changes: 10 additions & 12 deletions VisualStudioPlugin/Outlining/DddOutliningTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public IEnumerable<ITagSpan<DddOutlineTag>> GetTags(NormalizedSnapshotSpanCollec
var innerText = currentSnapshot.GetText(startPosition + 1, len);
yield return new TagSpan<DddOutlineTag>(
new SnapshotSpan(startLine.Start + region.StartOffset, endLine.End),
new DddOutlineTag(innerText, len, region.Rule, endLine.Start.Position + region.EndOffset + 1));
new DddOutlineTag(region.IsNested, innerText, len, region.Rule, endLine.Start.Position + region.EndOffset + 1));
}
}
}
Expand Down Expand Up @@ -130,18 +130,16 @@ private void ParseAndCache()
if (lastInfo.Level >= 0)
continue;
currentLevel--;
if (lastInfo.IsNested)
newRegions.Add(new Region
{
newRegions.Add(new Region
{
Rule = t.Value,
Level = currentLevel,
StartLine = currentRegion.StartLine,
StartOffset = currentRegion.StartOffset,
EndLine = t.Line - 1,
EndOffset = t.Column - 1
});
}
Rule = t.Value,
IsNested = lastInfo.IsNested,
Level = currentLevel,
StartLine = currentRegion.StartLine,
StartOffset = currentRegion.StartOffset,
EndLine = t.Line - 1,
EndOffset = t.Column - 1
});
lastInfo = currentLevel > 0 ? levelInfo[currentLevel - 1] : null;
if (lastInfo != null)
lastInfo.Level--;
Expand Down
1 change: 1 addition & 0 deletions VisualStudioPlugin/Outlining/Region.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ internal class Region : PartialRegion
{
public int EndLine;
public int EndOffset;
public bool IsNested;
}
}
15 changes: 12 additions & 3 deletions VisualStudioPlugin/Token/DddOutlineTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,38 @@ namespace DDDLanguage
{
internal class DddOutlineTag : IOutliningRegionTag
{
public readonly bool IsNested;
private readonly string Lines;
private readonly int Len;
internal readonly string Rule;
internal readonly int End;
private string Text;

public DddOutlineTag(string lines, int len, string rule, int end)
public DddOutlineTag(bool isNested, string lines, int len, string rule, int end)
{
this.IsNested = isNested;
this.Lines = lines;
this.Len = len;
this.Rule = rule;
this.End = end;
}

public object CollapsedForm { get { return "{ ... }"; } }
public object CollapsedForm { get { return IsNested ? "{ ... }" : "{}"; } }
public object CollapsedHintForm
{
get
{
if (!IsNested) return string.Empty;
if (Text == null)
{
var innerLines = Lines.Split('\n');
var maxSpace = innerLines.Take(10).Where(it => !string.IsNullOrWhiteSpace(it)).Min(it => it.Length - it.TrimStart().Length);
var nonEmpty = innerLines.Take(10).Where(it => !string.IsNullOrWhiteSpace(it)).ToList();
if (nonEmpty.Count == 0)
{
Text = string.Empty;
return Text;
}
var maxSpace = nonEmpty.Min(it => it.Length - it.TrimStart().Length);
Text =
string.Join("\n", innerLines.Take(10).Select(it => string.IsNullOrWhiteSpace(it) ? string.Empty : it.Substring(maxSpace)))
+ (Len > 999 || innerLines.Where(it => it.Length > 0).Count() > 10 ? Environment.NewLine + "..." : string.Empty);
Expand Down

0 comments on commit 66c27f1

Please sign in to comment.