Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lua LSP integration support #18

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Markdown.Avalonia.SyntaxHigh/Markdown.Avalonia.SyntaxHigh.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-preview6" />
<PackageReference Include="Markdown.Avalonia.Tight" Version="11.0.0-b1" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions Markdown.Avalonia.SyntaxHigh/StyleSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia.Styling;

namespace Markdown.Avalonia.SyntaxHigh;

public class StyleSetup
{
public IEnumerable<KeyValuePair<string, Action<Styles>>> GetOverrideStyles()
{
return new List<KeyValuePair<string, Action<Styles>>>();
}
}
78 changes: 78 additions & 0 deletions Markdown.Avalonia.SyntaxHigh/SyntaxSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Media;
using System.Text.RegularExpressions;

namespace Markdown.Avalonia.SyntaxHigh;

// It seems that the Markdown.Avalonia 11.0.0-b1 doesn't have a good support for lua
// syntax highlight, and in version v0.10.14 I can find the ways to custom it
// but there is no way to custom in 11.0.0-b1.
//
// So I write this class as a "plugin" to resolve this problem.
// And this should be followed as below:
// https://github.com/whistyun/Markdown.Avalonia/blob/8aec868dafe7798e0a71667bb4d587cd05760b7a/Markdown.Avalonia.Tight/Markdown.cs#L43-L47
// https://github.com/whistyun/Markdown.Avalonia/blob/v11.0.0-b1/Markdown.Avalonia.SyntaxHigh/SyntaxSetup.cs
//
// What's more, styles haven't been adapted, which can be referenced from:
// https://github.com/whistyun/Markdown.Avalonia/blob/8aec868dafe7798e0a71667bb4d587cd05760b7a/Markdown.Avalonia.Tight/MarkdownStyle.cs#L26-L30
// https://github.com/whistyun/Markdown.Avalonia/blob/v11.0.0-b1/Markdown.Avalonia.SyntaxHigh/StyleSetup.cs
//
// And this may be removed if Markdown.Avalonia updates.

public class SyntaxSetup
{
public static Func<string, string, Control>? CreateCodeBlock;

public IEnumerable<KeyValuePair<string, Func<Match, Control>>> GetOverrideConverters()
{
yield return new KeyValuePair<string, Func<Match, Control>>(
"CodeBlocksWithLangEvaluator",
CodeBlocksEvaluator);
}

private Border CodeBlocksEvaluator(Match match)
{
var lang = match.Groups[2].Value;
var code = match.Groups[3].Value;

if(string.IsNullOrEmpty(lang)) {
var ctxt = new TextBlock() {
Text = code,
TextWrapping = TextWrapping.NoWrap
};
ctxt.Classes.Add(Markdown.CodeBlockClass);

var scrl = new ScrollViewer();
scrl.Classes.Add(Markdown.CodeBlockClass);
scrl.Content = ctxt;
scrl.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;

var result = new Border();
result.Classes.Add(Markdown.CodeBlockClass);
result.Child = scrl;

return result;
} else {
// check wheither style is set
//if(!ThemeDetector.IsAvalonEditSetup) {
// SetupStyle();
//}

//var txtEdit = new TextEditor();
//txtEdit.Tag = lang;

//txtEdit.Text = code;
//txtEdit.HorizontalAlignment = HorizontalAlignment.Stretch;
//txtEdit.IsReadOnly = true;

var result = new Border();
result.Classes.Add(Markdown.CodeBlockClass);
if(CreateCodeBlock != null)
result.Child = CreateCodeBlock(lang, code);

return result;
}
}

}
18 changes: 18 additions & 0 deletions Mesen.sln
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SevenZip", "SevenZip\SevenZ
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lua", "Lua\Lua.vcxproj", "{B609E0A0-5050-4871-91D6-E760633BCDD1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Markdown.Avalonia.SyntaxHigh", "Markdown.Avalonia.SyntaxHigh\Markdown.Avalonia.SyntaxHigh.csproj", "{21CD6056-1F8E-414F-A0C6-136998B533BC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -150,6 +152,22 @@ Global
{B609E0A0-5050-4871-91D6-E760633BCDD1}.Release|Any CPU.ActiveCfg = Release|x64
{B609E0A0-5050-4871-91D6-E760633BCDD1}.Release|x64.ActiveCfg = Release|x64
{B609E0A0-5050-4871-91D6-E760633BCDD1}.Release|x64.Build.0 = Release|x64
{21CD6056-1F8E-414F-A0C6-136998B533BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.Debug|x64.ActiveCfg = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.Debug|x64.Build.0 = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.PGO Optimize|Any CPU.ActiveCfg = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.PGO Optimize|Any CPU.Build.0 = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.PGO Optimize|x64.ActiveCfg = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.PGO Optimize|x64.Build.0 = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.PGO Profile|Any CPU.ActiveCfg = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.PGO Profile|Any CPU.Build.0 = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.PGO Profile|x64.ActiveCfg = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.PGO Profile|x64.Build.0 = Debug|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.Release|Any CPU.Build.0 = Release|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.Release|x64.ActiveCfg = Release|Any CPU
{21CD6056-1F8E-414F-A0C6-136998B533BC}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading