-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Samir Boulema
committed
Nov 25, 2021
1 parent
a3570ab
commit ddecec3
Showing
14 changed files
with
251 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
<HasSharedItems>true</HasSharedItems> | ||
<SharedGUID>55d33626-0080-407a-bcda-52dafc2eb45c</SharedGUID> | ||
</PropertyGroup> | ||
<PropertyGroup Label="Configuration"> | ||
<Import_RootNamespace>CodeNav.Languages.CSS</Import_RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildThisFileDirectory)Mappers\BaseMapper.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Mappers\SyntaxMapper.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)Models\CodeStyleRuleItem.cs" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>55d33626-0080-407a-bcda-52dafc2eb45c</ProjectGuid> | ||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion> | ||
</PropertyGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" /> | ||
<PropertyGroup /> | ||
<Import Project="CodeNav.Languages.CSS.projitems" Label="Shared" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using CodeNav.Helpers; | ||
using CodeNav.Mappers; | ||
using CodeNav.Models; | ||
using ExCSS; | ||
using Microsoft.CodeAnalysis.Text; | ||
using System; | ||
using System.Windows.Media; | ||
using TextSpan = Microsoft.CodeAnalysis.Text.TextSpan; | ||
using Colors = System.Windows.Media.Colors; | ||
|
||
namespace CodeNav.Languages.CSS.Mappers | ||
{ | ||
public static class BaseMapper | ||
{ | ||
public static T MapBase<T>(Rule member, string id, ICodeViewUserControl control) where T : CodeItem | ||
{ | ||
var element = Activator.CreateInstance<T>(); | ||
|
||
var name = string.IsNullOrEmpty(id) ? "anonymous" : id; | ||
var startPos = member.StylesheetText.Range.Start.Position; | ||
var endPos = member.StylesheetText.Range.End.Position; | ||
|
||
element.Name = name; | ||
element.FullName = name; | ||
element.Id = name; | ||
element.Tooltip = name; | ||
element.StartLine = member.StylesheetText.Range.Start.Line - 1; | ||
element.StartLinePosition = new LinePosition(member.StylesheetText.Range.Start.Line - 1, 0); | ||
element.EndLine = member.StylesheetText.Range.End.Line - 1; | ||
element.EndLinePosition = new LinePosition(member.StylesheetText.Range.End.Line - 1, 0); | ||
element.Span = new TextSpan(startPos, endPos - startPos); | ||
element.ForegroundColor = Colors.Black; | ||
element.Access = CodeItemAccessEnum.Public; | ||
element.FontSize = SettingsHelper.Font.SizeInPoints; | ||
element.ParameterFontSize = SettingsHelper.Font.SizeInPoints - 1; | ||
element.FontFamily = new FontFamily(SettingsHelper.Font.FontFamily.Name); | ||
element.FontStyle = FontStyleMapper.Map(SettingsHelper.Font.Style); | ||
element.Control = control; | ||
element.FilePath = control.CodeDocumentViewModel.FilePath; | ||
|
||
return element; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using CodeNav.Languages.CSS.Models; | ||
using CodeNav.Mappers; | ||
using CodeNav.Models; | ||
using ExCSS; | ||
using Microsoft.CodeAnalysis; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Colors = System.Windows.Media.Colors; | ||
|
||
namespace CodeNav.Languages.CSS.Mappers | ||
{ | ||
public static class SyntaxMapper | ||
{ | ||
public static List<CodeItem> Map(Document document, ICodeViewUserControl control) | ||
=> Map(document.FilePath, control); | ||
|
||
public static List<CodeItem> Map(string filePath, ICodeViewUserControl control) | ||
{ | ||
if (!File.Exists(filePath)) | ||
{ | ||
return new List<CodeItem>(); | ||
} | ||
|
||
var text = File.ReadAllText(filePath); | ||
|
||
var ast = new StylesheetParser().Parse(text); | ||
|
||
return new List<CodeItem> | ||
{ | ||
new CodeNamespaceItem | ||
{ | ||
Id = "Namespace" + filePath, | ||
Kind = CodeItemKindEnum.Namespace, | ||
BorderColor = Colors.DarkGray, | ||
Members = MapMembers(ast, control) | ||
} | ||
}; | ||
} | ||
|
||
private static List<CodeItem> MapMembers(Stylesheet ast, ICodeViewUserControl control) | ||
{ | ||
if (ast?.Children?.Any() != true) | ||
{ | ||
return new List<CodeItem>(); | ||
} | ||
|
||
return ast.Children.SelectMany(c => MapMember(c, control)).ToList(); | ||
} | ||
|
||
private static List<CodeItem> MapMember(IStylesheetNode member, ICodeViewUserControl control) | ||
{ | ||
switch (member) | ||
{ | ||
case StyleRule styleRule: | ||
return MapStyleRule(styleRule, control); | ||
case Rule rule when rule.Type == RuleType.Page: | ||
return MapPageRule(rule, control); | ||
case Rule rule when rule.Type == RuleType.Namespace: | ||
return MapNamespaceRule(rule, control); | ||
case Rule rule when rule.Type == RuleType.Media: | ||
return MapMediaRule(rule, control); | ||
case Rule rule when rule.Type == RuleType.FontFace: | ||
return MapFontFaceRule(rule, control); | ||
default: | ||
break; | ||
} | ||
|
||
return new List<CodeItem>(); | ||
} | ||
|
||
private static List<CodeItem> MapStyleRule(StyleRule styleRule, ICodeViewUserControl control) | ||
{ | ||
var item = BaseMapper.MapBase<CodeStyleRuleItem>(styleRule, styleRule.SelectorText, control); | ||
|
||
item.Kind = CodeItemKindEnum.StyleRule; | ||
item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access); | ||
|
||
return new List<CodeItem> { item }; | ||
} | ||
|
||
private static List<CodeItem> MapPageRule(Rule rule, ICodeViewUserControl control) | ||
{ | ||
var item = BaseMapper.MapBase<CodeStyleRuleItem>(rule, "page", control); | ||
|
||
item.Kind = CodeItemKindEnum.PageRule; | ||
item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access); | ||
|
||
return new List<CodeItem> { item }; | ||
} | ||
|
||
private static List<CodeItem> MapNamespaceRule(Rule rule, ICodeViewUserControl control) | ||
{ | ||
var item = BaseMapper.MapBase<CodeStyleRuleItem>(rule, (rule as INamespaceRule).Prefix, control); | ||
|
||
item.Kind = CodeItemKindEnum.NamespaceRule; | ||
item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access); | ||
|
||
return new List<CodeItem> { item }; | ||
} | ||
|
||
private static List<CodeItem> MapMediaRule(Rule rule, ICodeViewUserControl control) | ||
{ | ||
var item = BaseMapper.MapBase<CodeClassItem>(rule, (rule as IMediaRule).Media.MediaText, control); | ||
|
||
item.Kind = CodeItemKindEnum.MediaRule; | ||
item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access); | ||
item.BorderColor = Colors.DarkGray; | ||
item.Members = (rule as IMediaRule).Rules.SelectMany(r => MapMember(r, control)).ToList(); | ||
|
||
return new List<CodeItem> { item }; | ||
} | ||
|
||
private static List<CodeItem> MapFontFaceRule(Rule rule, ICodeViewUserControl control) | ||
{ | ||
var fontRule = rule as IFontFaceRule; | ||
|
||
var item = BaseMapper.MapBase<CodeStyleRuleItem>(rule, $"{fontRule.Family} {fontRule.Weight}" , control); | ||
|
||
item.Kind = CodeItemKindEnum.FontFaceRule; | ||
item.Moniker = IconMapper.MapMoniker(item.Kind, item.Access); | ||
|
||
return new List<CodeItem> { item }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using CodeNav.Models; | ||
|
||
namespace CodeNav.Languages.CSS.Models | ||
{ | ||
public class CodeStyleRuleItem : CodeItem | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters