Skip to content

Commit

Permalink
Moved Severities into JSON file
Browse files Browse the repository at this point in the history
  • Loading branch information
madskristensen committed Jan 30, 2017
1 parent 308e98f commit 351c05a
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 548 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [x] Mark "unset" value as unsupported
- [x] Move schema into JSON file
- [x] Show hover tooltip for values
- [ ] Add XMLDoc comments
- [ ] Swith icons to the official .editorconfig icon
- [ ] Add item template for .editorconfig files

Expand Down
4 changes: 2 additions & 2 deletions Test/EditorConfigTest/ParseItemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class ParseItemTest
[TestMethod]
public void Equals()
{
var a = new ParseItem(default(EditorConfigDocument), ItemType.Property, new Span(10, 10), "a text");
var a = new ParseItem(default(EditorConfigDocument), ItemType.Keyword, new Span(10, 10), "a text");
var b = new ParseItem(default(EditorConfigDocument), ItemType.Section, new Span(20, 10), "b text");
var c = new ParseItem(default(EditorConfigDocument), ItemType.Property, new Span(10, 10), "a text");
var c = new ParseItem(default(EditorConfigDocument), ItemType.Keyword, new Span(10, 10), "a text");

Assert.IsTrue(a == c);
Assert.IsFalse(a != c);
Expand Down
2 changes: 1 addition & 1 deletion src/Classifier/EditorConfigClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public EditorConfigClassifier(IClassificationTypeRegistryService registry, IText
_map = _map ?? new Dictionary<ItemType, IClassificationType> {
{ ItemType.Comment, registry.GetClassificationType(PredefinedClassificationTypeNames.Comment)},
{ ItemType.Section, registry.GetClassificationType(PredefinedClassificationTypeNames.String)},
{ ItemType.Property, registry.GetClassificationType(PredefinedClassificationTypeNames.Identifier)},
{ ItemType.Keyword, registry.GetClassificationType(PredefinedClassificationTypeNames.Identifier)},
{ ItemType.Value, registry.GetClassificationType(PredefinedClassificationTypeNames.Keyword)},
{ ItemType.Severity, registry.GetClassificationType(PredefinedClassificationTypeNames.SymbolDefinition)},
};
Expand Down
10 changes: 4 additions & 6 deletions src/Completion/CompletionElementProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ public class CompletionElementProvider : IUIElementProvider<Completion, IComplet
{
public UIElement GetUIElement(Completion itemToRender, ICompletionSession context, UIElementType elementType)
{
if (elementType == UIElementType.Tooltip)
if (elementType == UIElementType.Tooltip &&
itemToRender.Properties.TryGetProperty("item", out ITooltip item) &&
!string.IsNullOrEmpty(item.Description))
{
if (SchemaCatalog.TryGetProperty(itemToRender.DisplayText, out Keyword prop))
return new Shared.EditorTooltip(prop);

if (SchemaCatalog.TryGetSeverity(itemToRender.DisplayText, out Severity severity))
return new Shared.EditorTooltip(severity);
return new Shared.EditorTooltip(item);
}

return null;
Expand Down
17 changes: 10 additions & 7 deletions src/Completion/CompletionSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public void AugmentCompletionSession(ICompletionSession session, IList<Completio
var parseItem = _document.ItemAtPosition(position);

// Property
if (string.IsNullOrWhiteSpace(line.GetText()) || parseItem?.ItemType == ItemType.Property)
if (string.IsNullOrWhiteSpace(line.GetText()) || parseItem?.ItemType == ItemType.Keyword)
{
var isInRoot = !_document.ParseItems.Exists(p => p.ItemType == ItemType.Section && p.Span.Start < position);
var items = isInRoot ? SchemaCatalog.Properties : SchemaCatalog.Properties.Where(i => i.Name != SchemaCatalog.Root);
var items = isInRoot ? SchemaCatalog.Keywords : SchemaCatalog.Keywords.Where(i => i.Name != SchemaCatalog.Root);

foreach (var property in items)
list.Add(CreateCompletion(property, property.Category));
Expand All @@ -53,7 +53,7 @@ public void AugmentCompletionSession(ICompletionSession session, IList<Completio
// Value
else if (parseItem?.ItemType == ItemType.Value)
{
if (SchemaCatalog.TryGetProperty(prev.Text, out Keyword item))
if (SchemaCatalog.TryGetKeyword(prev.Text, out Keyword item))
{
foreach (var value in item.Values)
list.Add(CreateCompletion(value));
Expand All @@ -70,22 +70,22 @@ public void AugmentCompletionSession(ICompletionSession session, IList<Completio
else
{
var prop = _document.PropertyAtPosition(position);
if (SchemaCatalog.TryGetProperty(prop?.Keyword?.Text, out Keyword key) && key.RequiresSeverity)
if (SchemaCatalog.TryGetKeyword(prop?.Keyword?.Text, out Keyword key) && key.RequiresSeverity)
AddSeverity(list);
}
}

if (!list.Any())
{
if (SchemaCatalog.TryGetProperty(prev?.Text, out Keyword property))
if (SchemaCatalog.TryGetKeyword(prev?.Text, out Keyword property))
{
var eq = line.GetText().IndexOf("=");

if (eq != -1)
{
var eqPos = eq + line.Start.Position;

if (triggerPoint.Value.Position > eqPos)
if (position > eqPos)
foreach (var value in property.Values)
list.Add(CreateCompletion(value));
}
Expand Down Expand Up @@ -154,7 +154,10 @@ private Completion4 CreateCompletion(ITooltip item, Category category = Category
automationText = category.ToString();
}

return new Completion4(text, item.Name, item.Description, item.Moniker, automationText, icon);
var completion = new Completion4(text, item.Name, item.Description, item.Moniker, automationText, icon);
completion.Properties.AddProperty("item", item);

return completion;
}

private ITrackingSpan FindTokenSpanAtPosition(ICompletionSession session)
Expand Down
22 changes: 11 additions & 11 deletions src/EditorConfig.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.VSSDK.BuildTools.15.0.25929-RC2\build\Microsoft.VSSDK.BuildTools.props" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.15.0.25929-RC2\build\Microsoft.VSSDK.BuildTools.props')" />
<Import Project="..\packages\Microsoft.VSSDK.BuildTools.15.0.26124-RC3\build\Microsoft.VSSDK.BuildTools.props" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.15.0.26124-RC3\build\Microsoft.VSSDK.BuildTools.props')" />
<PropertyGroup>
<MinimumVisualStudioVersion>$(VisualStudioVersion)</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down Expand Up @@ -181,8 +181,8 @@
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Schema\Keywords-schema.json" />
<Content Include="Schema\Keywords.json">
<None Include="Schema\EditorConfig-schema.json" />
<Content Include="Schema\EditorConfig.json">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="source.extension.vsixmanifest">
Expand Down Expand Up @@ -403,19 +403,19 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<ProjectExtensions>
<VisualStudio>
<UserProperties Schema_4EditorConfig_1json__JSONSchema="EditorConfig-schema.json" />
</VisualStudio>
</ProjectExtensions>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.VSSDK.BuildTools.15.0.25929-RC2\build\Microsoft.VSSDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VSSDK.BuildTools.15.0.25929-RC2\build\Microsoft.VSSDK.BuildTools.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.VSSDK.BuildTools.15.0.25929-RC2\build\Microsoft.VSSDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VSSDK.BuildTools.15.0.25929-RC2\build\Microsoft.VSSDK.BuildTools.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.VSSDK.BuildTools.15.0.26124-RC3\build\Microsoft.VSSDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VSSDK.BuildTools.15.0.26124-RC3\build\Microsoft.VSSDK.BuildTools.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.VSSDK.BuildTools.15.0.26124-RC3\build\Microsoft.VSSDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.VSSDK.BuildTools.15.0.26124-RC3\build\Microsoft.VSSDK.BuildTools.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.VSSDK.BuildTools.15.0.25929-RC2\build\Microsoft.VSSDK.BuildTools.targets" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.15.0.25929-RC2\build\Microsoft.VSSDK.BuildTools.targets')" />
<ProjectExtensions>
<VisualStudio>
<UserProperties Schema_4Keywords_1json__JSONSchema="Keywords-schema.json" Schema_4Keywords-schema_1json__JSONSchema="http://json-schema.org/draft-04/schema" />
</VisualStudio>
</ProjectExtensions>
<Import Project="..\packages\Microsoft.VSSDK.BuildTools.15.0.26124-RC3\build\Microsoft.VSSDK.BuildTools.targets" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.15.0.26124-RC3\build\Microsoft.VSSDK.BuildTools.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/EditorConfigDocumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private System.Threading.Tasks.Task ParseAsync()
// Property
else if (IsMatch(_property, text, out match))
{
var keyword = CreateParseItem(ItemType.Property, line, match.Groups["keyword"]);
var keyword = CreateParseItem(ItemType.Keyword, line, match.Groups["keyword"]);
AddToList(items, keyword);

var property = new Property(keyword);
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ParseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public enum ItemType
{
Comment,
Section,
Property,
Keyword,
Value,
Severity,
Unknown
Expand Down
31 changes: 15 additions & 16 deletions src/QuickInfo/EditorConfigQuickInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Text;
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -30,39 +31,37 @@ public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qiC
if (item == null)
return;

applicableToSpan = point.Value.Snapshot.CreateTrackingSpan(item.Span, SpanTrackingMode.EdgeNegative);

if (item.Errors.Any())
{
foreach (var error in item.Errors)
{
qiContent.Add(new Shared.EditorTooltip(error));
break;
return;
}
}
else if (item.ItemType == ItemType.Property && SchemaCatalog.TryGetProperty(item.Text, out Keyword property))

var property = _document.PropertyAtPosition(point.Value);

if (!SchemaCatalog.TryGetKeyword(property?.Keyword?.Text, out Keyword keyword))
return;

if (item.ItemType == ItemType.Keyword)
{
qiContent.Add(new Shared.EditorTooltip(property));
qiContent.Add(new Shared.EditorTooltip(keyword));
}
else if (item.ItemType == ItemType.Value)
{
var index = _document.ParseItems.IndexOf(item);
var value = keyword.Values.FirstOrDefault(v => v.Name.Equals(item.Text, StringComparison.OrdinalIgnoreCase));

if (index > 0)
{
var prev = _document.ParseItems.ElementAt(index - 1);
if (prev.ItemType == ItemType.Property && SchemaCatalog.TryGetProperty(prev.Text, out Keyword keyword))
{
var value = keyword.Values.FirstOrDefault(v => v.Name == item.Text && !string.IsNullOrEmpty(v.Description));
if (value != null)
qiContent.Add(new Shared.EditorTooltip(value));
}
}
if (value != null && !string.IsNullOrEmpty(value.Description))
qiContent.Add(new Shared.EditorTooltip(value));
}
else if (item.ItemType == ItemType.Severity && SchemaCatalog.TryGetSeverity(item.Text, out Severity severity))
{
qiContent.Add(new Shared.EditorTooltip(severity));
}

applicableToSpan = point.Value.Snapshot.CreateTrackingSpan(item.Span, SpanTrackingMode.EdgeNegative);
}

public void Dispose()
Expand Down
45 changes: 9 additions & 36 deletions src/Resources/Text.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions src/Resources/Text.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,6 @@
<data name="NotSupportedByVS" xml:space="preserve">
<value>Not supported by Visual Studio</value>
</data>
<data name="SeverityError" xml:space="preserve">
<value>When this style is not being followed, show a compiler error (red squiggle).</value>
</data>
<data name="SeverityNone" xml:space="preserve">
<value>Do not show anything to the user when this style is not being followed, however code generation features will generate in this style.</value>
</data>
<data name="SeveritySuggestion" xml:space="preserve">
<value>When this style is not being followed, show it to the user as a suggestion (underlying dots on the first two characters).</value>
</data>
<data name="SeverityWarning" xml:space="preserve">
<value>When this style is not being followed, show a compiler warning (green squiggle).</value>
</data>
<data name="ValidateOnlyRootAllowed" xml:space="preserve">
<value>Only "root" is allowed outside a section</value>
</data>
Expand Down Expand Up @@ -184,4 +172,7 @@
<data name="ValidationUnknownElement" xml:space="preserve">
<value>Syntax error. Element not valid at current location</value>
</data>
<data name="ValueUnset" xml:space="preserve">
<value>For any standard property, a value of "unset" is to remove the effect of that property, even if it has been set before.</value>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "array",
"type": "object",

"definitions": {
"keyword": {
Expand All @@ -25,10 +25,35 @@
"enum": [ true ]
}
}
},
"severities": {
"type": "object",
"required": ["name", "description"],
"additionalProperties": false,

"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
}
}
}
},

"items": {
"$ref": "#/definitions/keyword"
"properties": {
"properties": {
"type": "array",
"items": {
"$ref": "#/definitions/keyword"
}
},
"severities": {
"type": "array",
"items": {
"$ref": "#/definitions/severities"
}
}
}
}
Loading

0 comments on commit 351c05a

Please sign in to comment.