This repository was archived by the owner on Sep 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Add directive attribute support. #367
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
136 changes: 136 additions & 0 deletions
136
src/Microsoft.AspNetCore.Razor.LanguageServer/Completion/CompletionItemExtensions.cs
This file contains hidden or 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,136 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Git diff failure here. Did not touch all of this. |
||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.CodeAnalysis.Razor.Completion; | ||
using Newtonsoft.Json.Linq; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
|
||
namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion | ||
{ | ||
internal static class CompletionItemExtensions | ||
{ | ||
private const string TagHelperElementDataKey = "_TagHelperElementData_"; | ||
private const string TagHelperAttributeDataKey = "_TagHelperAttributes_"; | ||
private const string AttributeCompletionDataKey = "_AttributeCompletion_"; | ||
private const string RazorCompletionItemKind = "_CompletionItemKind_"; | ||
|
||
public static void SetRazorCompletionKind(this CompletionItem completion, RazorCompletionItemKind completionItemKind) | ||
{ | ||
if (completion is null) | ||
{ | ||
throw new ArgumentNullException(nameof(completion)); | ||
} | ||
|
||
var data = completion.Data ?? new JObject(); | ||
data[RazorCompletionItemKind] = JToken.FromObject(completionItemKind); | ||
completion.Data = data; | ||
} | ||
|
||
public static bool TryGetRazorCompletionKind(this CompletionItem completion, out RazorCompletionItemKind completionItemKind) | ||
{ | ||
if (completion is null) | ||
{ | ||
throw new ArgumentNullException(nameof(completion)); | ||
} | ||
|
||
if (completion.Data is JObject data && data.ContainsKey(RazorCompletionItemKind)) | ||
{ | ||
completionItemKind = data[RazorCompletionItemKind].ToObject<RazorCompletionItemKind>(); | ||
return true; | ||
} | ||
|
||
completionItemKind = default; | ||
return false; | ||
} | ||
|
||
public static bool IsTagHelperElementCompletion(this CompletionItem completion) | ||
{ | ||
if (completion.Data is JObject data && data.ContainsKey(TagHelperElementDataKey)) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static bool IsTagHelperAttributeCompletion(this CompletionItem completion) | ||
{ | ||
if (completion.Data is JObject data && data.ContainsKey(TagHelperAttributeDataKey)) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static void SetDescriptionInfo(this CompletionItem completion, ElementDescriptionInfo elementDescriptionInfo) | ||
{ | ||
var data = completion.Data ?? new JObject(); | ||
data[TagHelperElementDataKey] = JObject.FromObject(elementDescriptionInfo); | ||
completion.Data = data; | ||
} | ||
|
||
public static void SetDescriptionInfo(this CompletionItem completion, AttributeDescriptionInfo attributeDescriptionInfo) | ||
{ | ||
var data = completion.Data ?? new JObject(); | ||
data[TagHelperAttributeDataKey] = JObject.FromObject(attributeDescriptionInfo); | ||
completion.Data = data; | ||
} | ||
|
||
public static void SetDescriptionInfo(this CompletionItem completion, AttributeCompletionDescription attributeDescriptionInfo) | ||
{ | ||
if (completion is null) | ||
{ | ||
throw new ArgumentNullException(nameof(completion)); | ||
} | ||
|
||
if (attributeDescriptionInfo is null) | ||
{ | ||
throw new ArgumentNullException(nameof(attributeDescriptionInfo)); | ||
} | ||
|
||
var data = completion.Data ?? new JObject(); | ||
data[AttributeCompletionDataKey] = JObject.FromObject(attributeDescriptionInfo); | ||
completion.Data = data; | ||
} | ||
|
||
public static ElementDescriptionInfo GetElementDescriptionInfo(this CompletionItem completion) | ||
{ | ||
if (completion.Data is JObject data && data.ContainsKey(TagHelperElementDataKey)) | ||
{ | ||
var descriptionInfo = data[TagHelperElementDataKey].ToObject<ElementDescriptionInfo>(); | ||
return descriptionInfo; | ||
} | ||
|
||
return ElementDescriptionInfo.Default; | ||
} | ||
|
||
public static AttributeDescriptionInfo GetTagHelperAttributeDescriptionInfo(this CompletionItem completion) | ||
{ | ||
if (completion.Data is JObject data && data.ContainsKey(TagHelperAttributeDataKey)) | ||
{ | ||
var descriptionInfo = data[TagHelperAttributeDataKey].ToObject<AttributeDescriptionInfo>(); | ||
return descriptionInfo; | ||
} | ||
|
||
return AttributeDescriptionInfo.Default; | ||
} | ||
|
||
public static AttributeCompletionDescription GetAttributeDescriptionInfo(this CompletionItem completion) | ||
{ | ||
if (completion is null) | ||
{ | ||
throw new ArgumentNullException(nameof(completion)); | ||
} | ||
|
||
if (completion.Data is JObject data && data.ContainsKey(AttributeCompletionDataKey)) | ||
{ | ||
var descriptionInfo = data[AttributeCompletionDataKey].ToObject<AttributeCompletionDescription>(); | ||
return descriptionInfo; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the changes here are a direct copy from Razor. Sadly our serialization logic is in the VS windows specific binary.