-
Notifications
You must be signed in to change notification settings - Fork 4
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
8f627b7
commit 497b779
Showing
29 changed files
with
298 additions
and
271 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,54 @@ | ||
using OneWare.SDK.Helpers; | ||
using OneWare.SDK.NativeTools; | ||
using OneWare.SDK.Services; | ||
|
||
namespace OneWare.Core.Services; | ||
|
||
public class NativeToolService(IHttpService httpService, ISettingsService settingsService, IPaths paths, ILogger logger) : INativeToolService | ||
{ | ||
private readonly Dictionary<PlatformId, Dictionary<string, NativeTool>> _nativeTools = new(); | ||
|
||
public NativeTool Register(string id, string url, params PlatformId[] supportedPlatforms) | ||
{ | ||
var nativeTool = new NativeTool(id, url, Path.Combine(paths.NativeToolsDirectory, id)); | ||
foreach (var platform in supportedPlatforms) | ||
{ | ||
_nativeTools.TryAdd(platform, new Dictionary<string, NativeTool>()); | ||
_nativeTools[platform].Add(id, nativeTool); | ||
} | ||
return nativeTool; | ||
} | ||
|
||
public NativeTool? Get(string key) | ||
{ | ||
if (_nativeTools.TryGetValue(PlatformHelper.Platform, out var platformTools)) | ||
{ | ||
if (platformTools.TryGetValue(key, out var nativeTool)) | ||
{ | ||
return nativeTool; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public async Task InstallAsync(NativeTool tool) | ||
{ | ||
logger.Log($"Downloading {tool.Id}..."); | ||
|
||
await DownloadNativeToolAsync(tool); | ||
|
||
foreach (var shortCut in tool.ShortCuts) | ||
{ | ||
if(shortCut.Value.SettingKey != null) | ||
settingsService.SetSettingValue(shortCut.Value.SettingKey, Path.Combine(tool.FullPath, shortCut.Value.RelativePath)); | ||
} | ||
settingsService.Save(paths.SettingsPath); | ||
|
||
logger.Log($"Download {tool.Id} finished!"); | ||
} | ||
|
||
private async Task DownloadNativeToolAsync(NativeTool tool) | ||
{ | ||
await httpService.DownloadAndExtractArchiveAsync(tool.Url, Path.Combine(paths.NativeToolsDirectory, tool.Id)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,19 +1,33 @@ | ||
using OneWare.SDK.Services; | ||
using OneWare.SDK.Helpers; | ||
using OneWare.SDK.Services; | ||
using Prism.Ioc; | ||
using Prism.Modularity; | ||
|
||
namespace OneWare.Cpp; | ||
|
||
public class CppModule : IModule | ||
{ | ||
public const string LspName = "clangd"; | ||
public const string LspPathSetting = "CppModule_ClangdPath"; | ||
|
||
public void RegisterTypes(IContainerRegistry containerRegistry) | ||
{ | ||
|
||
} | ||
|
||
public void OnInitialized(IContainerProvider containerProvider) | ||
{ | ||
containerProvider.Resolve<IErrorService>().RegisterErrorSource("Clang"); | ||
var nativeToolService = containerProvider.Resolve<INativeToolService>(); | ||
|
||
nativeToolService.Register(LspName, "https://github.com/clangd/clangd/releases/download/17.0.3/clangd-windows-17.0.3.zip", PlatformId.WinX64) | ||
.WithShortcut("LSP", Path.Combine("clangd_17.0.3", "bin", "clangd.exe"), LspPathSetting); | ||
|
||
containerProvider.Resolve<ISettingsService>().RegisterTitledPath("Languages", "C++", LspPathSetting, "Clangd Path", "Path for clangd executable", | ||
nativeToolService.Get(LspName)!.GetShorcutPath("LSP")!, | ||
null, containerProvider.Resolve<IPaths>().PackagesDirectory, File.Exists); | ||
|
||
containerProvider.Resolve<IErrorService>().RegisterErrorSource(LspName); | ||
|
||
containerProvider.Resolve<ILanguageManager>().RegisterService(typeof(LanguageServiceCpp),false, ".cpp", ".h", ".c", ".hpp"); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,25 +22,15 @@ | |
|
||
namespace OneWare.SDK.LanguageService | ||
{ | ||
public abstract class LanguageServiceLsp : LanguageServiceBase | ||
public abstract class LanguageServiceLsp(string name, string? workspace) : LanguageServiceBase(name, workspace) | ||
{ | ||
private readonly Dictionary<ProgressToken, (ApplicationProcess, string)> _tokenRegister = new(); | ||
private LanguageClient? Client { get; set; } | ||
|
||
private CancellationTokenSource? _cancellation; | ||
private IChildProcess? _process; | ||
private string? Arguments { get; set; } | ||
private string? ExecutablePath { get; set; } | ||
|
||
protected LanguageServiceLsp(string name, string? executablePath, string? arguments, string? workspace) : base(name, workspace) | ||
{ | ||
if (executablePath != null && (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))) | ||
{ | ||
PlatformHelper.ChmodFile(executablePath); | ||
} | ||
ExecutablePath = executablePath; | ||
Arguments = arguments; | ||
} | ||
protected string? Arguments { get; set; } | ||
protected string? ExecutablePath { get; set; } | ||
|
||
public override async Task ActivateAsync() | ||
{ | ||
|
@@ -53,6 +43,11 @@ public override async Task ActivateAsync() | |
return; | ||
} | ||
|
||
if ((RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))) | ||
{ | ||
PlatformHelper.ChmodFile(ExecutablePath); | ||
} | ||
|
||
_cancellation = new CancellationTokenSource(); | ||
|
||
if (ExecutablePath.StartsWith("wss://") || ExecutablePath.StartsWith("ws://")) | ||
|
@@ -142,11 +137,8 @@ await Dispatcher.UIThread.InvokeAsync(async () => | |
_cancellation?.Cancel(); | ||
Check warning on line 137 in src/OneWare.SDK/LanguageService/LanguageServiceLsp.cs
|
||
_process?.Kill(); | ||
} | ||
|
||
/// <summary> | ||
/// After Activate | ||
/// </summary> | ||
protected async Task InitAsync(Stream input, Stream output, Action<LanguageClientOptions>? customOptions = null) | ||
|
||
private async Task InitAsync(Stream input, Stream output, Action<LanguageClientOptions>? customOptions = null) | ||
{ | ||
Client = LanguageClient.PreInit( | ||
options => | ||
|
@@ -165,7 +157,6 @@ protected async Task InitAsync(Stream input, Stream output, Action<LanguageClien | |
options.OnLogTrace(x => ContainerLocator.Container.Resolve<ILogger>()?.Log(x.Message, ConsoleColor.Red)); | ||
options.OnPublishDiagnostics(PublishDiag); | ||
options.OnApplyWorkspaceEdit(ApplyWorkspaceEditAsync); | ||
options.EnableDynamicRegistration(); | ||
options.OnShowMessage(x => ContainerLocator.Container.Resolve<ILogger>()?.Log(x.Message, ConsoleColor.DarkCyan)); | ||
options.OnTelemetryEvent(x => { ContainerLocator.Container.Resolve<ILogger>()?.Log(x, ConsoleColor.Magenta); }); | ||
|
||
|
@@ -250,6 +241,7 @@ protected async Task InitAsync(Stream input, Stream output, Action<LanguageClien | |
ValueSet = new Container<CompletionItemTag>(CompletionItemTag.Deprecated) | ||
} | ||
}, | ||
LabelDetailsSupport = true, | ||
}, | ||
CompletionItemKind = new CompletionItemKindCapabilityOptions | ||
{ | ||
|
30 changes: 30 additions & 0 deletions
30
src/OneWare.SDK/LanguageService/LanguageServiceLspAutoDownload.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,30 @@ | ||
using DynamicData.Binding; | ||
using OneWare.SDK.NativeTools; | ||
using OneWare.SDK.Services; | ||
using OneWare.SDK.ViewModels; | ||
|
||
namespace OneWare.SDK.LanguageService; | ||
|
||
public abstract class LanguageServiceLspAutoDownload : LanguageServiceLsp | ||
{ | ||
private readonly Func<Task> _installTask; | ||
protected LanguageServiceLspAutoDownload(IObservable<string> executablePath, Func<Task> install, string name, string? workspace) | ||
: base(name, workspace) | ||
{ | ||
_installTask = install; | ||
|
||
executablePath.Subscribe(x => | ||
{ | ||
ExecutablePath = x; | ||
}); | ||
} | ||
|
||
public override async Task ActivateAsync() | ||
{ | ||
if (!File.Exists(ExecutablePath)) | ||
{ | ||
await _installTask.Invoke(); | ||
} | ||
await base.ActivateAsync(); | ||
} | ||
} |
Oops, something went wrong.