-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
b1fd1d5
commit a06cc1f
Showing
11 changed files
with
1,467 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
src/OneWare.Core/Extensions/TextMate/CustomTextMateRegistryOptions.cs
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,68 @@ | ||
using Avalonia.Platform; | ||
using TextMateSharp.Grammars; | ||
using TextMateSharp.Internal.Grammars.Reader; | ||
using TextMateSharp.Internal.Types; | ||
using TextMateSharp.Registry; | ||
using TextMateSharp.Themes; | ||
|
||
namespace OneWare.Core.Extensions.TextMate; | ||
|
||
public class CustomTextMateRegistryOptions : IRegistryOptions | ||
{ | ||
private List<TextMateLanguage> _availableLanguages = new(); | ||
|
||
private readonly RegistryOptions _defaultRegistryOptions = new(ThemeName.DarkPlus); | ||
|
||
public void RegisterLanguage(string id, string grammarPath, params string[] extensions) | ||
{ | ||
_availableLanguages.Add(new TextMateLanguage() | ||
{ | ||
Id = id, | ||
GrammarPath = grammarPath, | ||
Extensions = extensions | ||
}); | ||
} | ||
|
||
public IRawGrammar GetGrammar(string scopeName) | ||
{ | ||
var g = _availableLanguages.FirstOrDefault(x => x.Id == scopeName); | ||
|
||
if (g == null) return _defaultRegistryOptions.GetGrammar(scopeName); | ||
using var s = new StreamReader(AssetLoader.Open(new Uri(g.GrammarPath))); | ||
{ | ||
return GrammarReader.ReadGrammarSync(s); | ||
} | ||
} | ||
|
||
public ICollection<string> GetInjections(string scopeName) | ||
{ | ||
return _defaultRegistryOptions.GetInjections(scopeName); | ||
} | ||
|
||
public Language? GetLanguageByExtension(string extension) | ||
{ | ||
var def = _availableLanguages.FirstOrDefault(x => x.Extensions.Contains(extension)); | ||
if (def != null) | ||
return new Language() | ||
{ | ||
Id = def.Id, | ||
}; | ||
return _defaultRegistryOptions.GetLanguageByExtension(extension); | ||
} | ||
|
||
public string GetScopeByLanguageId(string languageId) | ||
{ | ||
var r = _availableLanguages.FirstOrDefault(x => x.Id == languageId); | ||
return r?.Id ?? _defaultRegistryOptions.GetScopeByLanguageId(languageId); | ||
} | ||
|
||
public IRawTheme GetDefaultTheme() | ||
{ | ||
return _defaultRegistryOptions.GetDefaultTheme(); | ||
} | ||
public IRawTheme GetTheme(string scopeName) | ||
{ | ||
return _defaultRegistryOptions.GetTheme(scopeName); | ||
} | ||
public IRawTheme LoadTheme(ThemeName name) => _defaultRegistryOptions.LoadTheme(name); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/OneWare.Core/Extensions/TextMate/JsonSerializationContext.cs
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,15 @@ | ||
using System.Text.Json.Serialization; | ||
using TextMateSharp.Grammars; | ||
|
||
namespace OneWare.Core.Extensions.TextMate; | ||
|
||
[JsonSerializable(typeof(GrammarDefinition))] | ||
[JsonSerializable(typeof(LanguageSnippets))] | ||
[JsonSerializable(typeof(LanguageSnippet))] | ||
[JsonSerializable(typeof(LanguageConfiguration))] | ||
[JsonSerializable(typeof(EnterRule))] | ||
[JsonSerializable(typeof(AutoPair))] | ||
[JsonSerializable(typeof(IList<string>))] | ||
internal sealed partial class JsonSerializationContext : JsonSerializerContext | ||
{ | ||
} |
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 @@ | ||
namespace OneWare.Core.Extensions.TextMate; | ||
|
||
public class TextMateLanguage | ||
{ | ||
public IEnumerable<string> Extensions { get; set; } | ||
public string GrammarPath { get; set; } | ||
public string Id { get; set; } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"comments": { | ||
"lineComment": "--", | ||
"blockComment": [] | ||
}, | ||
"brackets": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"] | ||
] | ||
} |
Oops, something went wrong.