Skip to content
Merged
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
20 changes: 20 additions & 0 deletions THIRD-PARTY-NOTICES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,29 @@ into OneWare Studio regardless of OneWare's own license:
The full GPL v2 text accompanies the libgit2 distribution in the
LibGit2Sharp.NativeBinaries package (libgit2/libgit2.license.txt).

================================================================================
SYNTAX HIGHLIGHTING GRAMMARS
================================================================================
The Verilog, SystemVerilog, and Verilog filelist grammars were imported from
https://github.com/mshr-h/vscode-verilog-hdl-support at revision
e6a5a2b76055dd7acbdc7420060e0314cb86e8dd.

The SystemVerilog grammar is derived from VSCode-SystemVerilog:
Copyright (c) 2018 Eirik Prestegårdshus. It is licensed under the MIT License
reproduced below.

The Verilog grammar is derived from the TextMate Verilog Bundle:

Permission to copy, use, modify, sell and distribute this software is granted.
This software is provided "as is" without express or implied warranty, and
with no claim as to its suitability for any purpose.

================================================================================
COMPONENTS UNDER THE MIT LICENSE
================================================================================
- VSCode-SystemVerilog syntax grammar (revision e6a5a2b76055dd7acbdc7420060e0314cb86e8dd)
Copyright (c) 2018 Eirik Prestegårdshus
Source: https://github.com/mshr-h/vscode-verilog-hdl-support
- Asmichi.ChildProcess 0.18.0
- Avalonia 11.3.11
- Avalonia 11.3.12
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Avalonia.LogicalTree;

namespace OneWare.ApplicationCommands.Tabs;

public class CommandManagerSymbolsTab(ILogical logical) : CommandManagerTabBase("Symbols", logical)
{
public override string SearchBarText => "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using CommunityToolkit.Mvvm.Input;
using DynamicData;
using DynamicData.Binding;
using OneWare.ApplicationCommands.Models;
using OneWare.ApplicationCommands.Tabs;
using OneWare.ApplicationCommands.Views;
using OneWare.Essentials.Commands;
Expand All @@ -28,21 +29,28 @@ public partial class CommandManagerViewModel : FlexibleWindowViewModelBase
private readonly IApplicationCommandService _applicationCommandService;

private readonly IProjectExplorerService _projectExplorerService;
private readonly ILanguageManager _languageManager;
private readonly IMainDockService _mainDockService;
private readonly IWindowService _windowService;

[ObservableProperty] private CommandManagerTabBase _selectedTab;

private readonly CommandManagerAllTab _allTab;
private readonly CommandManagerFilesTab _filesTab;
private readonly CommandManagerSymbolsTab _symbolsTab;
private readonly CommandManagerActionsTab _actionsTab;
private readonly IReadOnlyCollection<IApplicationCommand> _staticCommands;
private CancellationTokenSource _fileSearchCancellation = new();
private CancellationTokenSource _symbolSearchCancellation = new();

public CommandManagerViewModel(ILogical logical, IApplicationCommandService commandService,
IProjectExplorerService projectExplorerService, IWindowService windowService)
IProjectExplorerService projectExplorerService, IWindowService windowService,
ILanguageManager languageManager, IMainDockService mainDockService)
{
ActiveFocus = logical;
_projectExplorerService = projectExplorerService;
_languageManager = languageManager;
_mainDockService = mainDockService;
_applicationCommandService = commandService;
_windowService = windowService;
_staticCommands = commandService.ApplicationCommands.ToList();
Expand All @@ -57,6 +65,11 @@ public CommandManagerViewModel(ILogical logical, IApplicationCommandService comm
Items = new ObservableCollection<IApplicationCommand>()
};
Tabs.Add(_filesTab);
_symbolsTab = new CommandManagerSymbolsTab(logical)
{
Items = new ObservableCollection<IApplicationCommand>()
};
Tabs.Add(_symbolsTab);
_actionsTab = new CommandManagerActionsTab(logical)
{
Items = commandService.ApplicationCommands
Expand All @@ -72,6 +85,9 @@ public CommandManagerViewModel(ILogical logical, IApplicationCommandService comm
_filesTab.WhenValueChanged(x => x.SearchText)
.Throttle(TimeSpan.FromMilliseconds(150))
.Subscribe(text => _ = UpdateFileSearchAsync(_filesTab, text));
_symbolsTab.WhenValueChanged(x => x.SearchText)
.Throttle(TimeSpan.FromMilliseconds(150))
.Subscribe(text => _ = UpdateSymbolSearchAsync(text));
}

public static KeyGesture ChangeShortcutGesture => new(Key.Enter, PlatformHelper.ControlKey);
Expand Down Expand Up @@ -164,6 +180,61 @@ private IReadOnlyList<IApplicationCommand> FindFileCommands(string searchText, C
return sorted;
}

private async Task UpdateSymbolSearchAsync(string? searchText)
{
await _symbolSearchCancellation.CancelAsync();
_symbolSearchCancellation.Dispose();
_symbolSearchCancellation = new CancellationTokenSource();
var token = _symbolSearchCancellation.Token;

if (string.IsNullOrWhiteSpace(searchText) || _mainDockService.CurrentDocument is not IEditor editor)
{
await Dispatcher.UIThread.InvokeAsync(() => ApplySymbolCommands([]));
return;
}

var languageService = _languageManager.GetLanguageService(editor.FullPath);
if (languageService == null)
{
await Dispatcher.UIThread.InvokeAsync(() => ApplySymbolCommands([]));
return;
}

IsSearching = true;
var symbols = await languageService.RequestWorkspaceSymbolsAsync(searchText);
IsSearching = false;
if (token.IsCancellationRequested) return;

var commands = symbols?
.Where(symbol => symbol.Location.IsLocation && symbol.Location.Location != null)
.Select(symbol =>
{
var location = symbol.Location.Location!;
var path = location.Uri.GetFileSystemPath();
return (IApplicationCommand)new OpenSymbolApplicationCommand(symbol.Name, path,
location.Range.Start.Line, location.Range.Start.Character)
{
Detail = string.IsNullOrWhiteSpace(symbol.ContainerName)
? Path.GetFileName(path)
: $"{symbol.ContainerName} - {Path.GetFileName(path)}"
};
})
.Take(MaxFileResults)
.ToList() ?? [];

await Dispatcher.UIThread.InvokeAsync(() => ApplySymbolCommands(commands));
}

private void ApplySymbolCommands(IReadOnlyList<IApplicationCommand> commands)
{
_symbolsTab.Items.Clear();
_symbolsTab.Items.AddRange(commands);
_symbolsTab.VisibleItems = commands
.Select(command => new CommandManagerItemModel(command, command.CanExecute(ActiveFocus)))
.ToList();
_symbolsTab.SelectedItem = _symbolsTab.VisibleItems.FirstOrDefault();
}

private static int ScoreFileMatch(string relativePath, string searchText)
{
var fileName = Path.GetFileName(relativePath);
Expand Down
4 changes: 2 additions & 2 deletions src/OneWare.Core/Services/FileIconService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public FileIconService(ILogger logger)
RegisterFileIcon("GhdpFileIcon", ".ghdp");
RegisterFileIcon("VhdpFileIcon", ".vhdp");
RegisterFileIcon("VhdlFileIcon", ".vhd", ".vhdl");
RegisterFileIcon("VerilogFileIcon", ".v");
RegisterFileIcon("VerilogFileIcon", ".v", ".vh");
RegisterFileIcon("QsysFileIcon", ".qsys");
RegisterFileIcon("SystemVerilogFileIcon", ".sv");
RegisterFileIcon("SystemVerilogFileIcon", ".sv", ".svh");
RegisterFileIcon("SimpleIcons.Arduino", ".ino");
RegisterFileIcon("Ionicons.LogoJavascript", ".js");
RegisterFileIcon("FontAwesome.PythonBrands", ".py");
Expand Down
43 changes: 34 additions & 9 deletions src/OneWare.Core/Styles/Icons.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -617,25 +617,50 @@
</DrawingImage>
<DrawingImage x:Key="VhdlFileIcon">
<DrawingGroup>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="Gray"
Geometry="F1 M 7.04631,12L 3.74546,4.23796L 6.03637,4.23796L 7.55767,8.20061L 8,9.52305C 8.11591,9.18719 8.18835,8.96562 8.21733,8.85834C 8.28892,8.6391 8.36477,8.41986 8.44489,8.20061L 9.96364,4.23796L 12.2545,4.23796L 8.99972,12L 7.04631,12 Z " />
<GeometryDrawing Brush="#00FFFFFF" Geometry="M0,0 L16,0 16,16 0,16 Z" />
<GeometryDrawing Geometry="M1,5 L3,5 M1,8 L3,8 M1,11 L3,11 M13,5 L15,5 M13,8 L15,8 M13,11 L15,11">
<GeometryDrawing.Pen>
<Pen Brush="#7C6CF2" Thickness="1.2" LineCap="Round" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Brush="#7C6CF2"
Geometry="M3,1 L10,1 14,5 14,14.25 C14,14.66 13.66,15 13.25,15 L3.75,15 C3.34,15 3,14.66 3,14.25 Z" />
<GeometryDrawing Brush="#A99DF8" Geometry="M10,1 L10,5 14,5 Z" />
<GeometryDrawing Brush="White"
Geometry="M4.2,6 L5.45,6 6.35,10.65 7.25,6 8.5,6 7.05,12 5.65,12 Z M9.1,6 L10.2,6 10.2,8.25 11.55,8.25 11.55,6 12.65,6 12.65,12 11.55,12 11.55,9.35 10.2,9.35 10.2,12 9.1,12 Z" />
</DrawingGroup>
</DrawingImage>

<DrawingImage x:Key="VerilogFileIcon">
<DrawingGroup>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="#00ffbf"
Geometry="F1 M 7.04631,12L 3.74546,4.23796L 6.03637,4.23796L 7.55767,8.20061L 8,9.52305C 8.11591,9.18719 8.18835,8.96562 8.21733,8.85834C 8.28892,8.6391 8.36477,8.41986 8.44489,8.20061L 9.96364,4.23796L 12.2545,4.23796L 8.99972,12L 7.04631,12 Z " />
<GeometryDrawing Brush="#00FFFFFF" Geometry="M0,0 L16,0 16,16 0,16 Z" />
<GeometryDrawing Geometry="M1,5 L3,5 M1,8 L3,8 M1,11 L3,11 M13,5 L15,5 M13,8 L15,8 M13,11 L15,11">
<GeometryDrawing.Pen>
<Pen Brush="#00A98F" Thickness="1.2" LineCap="Round" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Brush="#00A98F"
Geometry="M3,1 L10,1 14,5 14,14.25 C14,14.66 13.66,15 13.25,15 L3.75,15 C3.34,15 3,14.66 3,14.25 Z" />
<GeometryDrawing Brush="#65D6C5" Geometry="M10,1 L10,5 14,5 Z" />
<GeometryDrawing Brush="White"
Geometry="M4.35,5.5 L6.15,5.5 8.5,11.05 10.85,5.5 12.65,5.5 9.35,12.5 7.65,12.5 Z" />
</DrawingGroup>
</DrawingImage>

<DrawingImage x:Key="SystemVerilogFileIcon">
<DrawingGroup>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="#ff6eb4"
Geometry="F1 M 7.04631,12L 3.74546,4.23796L 6.03637,4.23796L 7.55767,8.20061L 8,9.52305C 8.11591,9.18719 8.18835,8.96562 8.21733,8.85834C 8.28892,8.6391 8.36477,8.41986 8.44489,8.20061L 9.96364,4.23796L 12.2545,4.23796L 8.99972,12L 7.04631,12 Z " />
<GeometryDrawing Brush="#00FFFFFF" Geometry="M0,0 L16,0 16,16 0,16 Z" />
<GeometryDrawing Geometry="M1,5 L3,5 M1,8 L3,8 M1,11 L3,11 M13,5 L15,5 M13,8 L15,8 M13,11 L15,11">
<GeometryDrawing.Pen>
<Pen Brush="#E548A0" Thickness="1.2" LineCap="Round" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Brush="#E548A0"
Geometry="M3,1 L10,1 14,5 14,14.25 C14,14.66 13.66,15 13.25,15 L3.75,15 C3.34,15 3,14.66 3,14.25 Z" />
<GeometryDrawing Brush="#F294C8" Geometry="M10,1 L10,5 14,5 Z" />
<GeometryDrawing Brush="White"
Geometry="M4,6.1 C4,5.49 4.49,5 5.1,5 L7.2,5 7.2,6.15 5.3,6.15 C5.14,6.15 5.05,6.24 5.05,6.4 5.05,6.53 5.12,6.61 5.25,6.66 L6.45,7.12 C7.04,7.35 7.4,7.87 7.4,8.5 7.4,9.33 6.73,10 5.9,10 L4,10 4,8.85 5.85,8.85 C6.1,8.85 6.25,8.7 6.25,8.5 6.25,8.34 6.16,8.22 6,8.16 L4.85,7.72 C4.32,7.52 4,6.9 4,6.1 Z M7.8,5 L9.15,5 10.35,9.15 11.55,5 12.9,5 11.05,11 9.65,11 Z" />
<GeometryDrawing Brush="#FFD5EC" Geometry="M5.1,11.25 L11.8,11.25 11.8,12.4 5.1,12.4 Z" />
</DrawingGroup>
</DrawingImage>

Expand Down
5 changes: 5 additions & 0 deletions src/OneWare.Core/ViewModels/Windows/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public MainWindowViewModel(IPaths paths, IApplicationStateService applicationSta
Header = "Find Files",
Command = new RelayCommand(() => OpenManager(GetMainView(), "Files")),
InputGesture = new KeyGesture(Key.A, PlatformHelper.ControlKey | KeyModifiers.Shift)
}, new MenuItemModel("FindSymbols")
{
Header = "Go to Symbol",
Command = new RelayCommand(() => OpenManager(GetMainView(), "Symbols")),
InputGesture = new KeyGesture(Key.O, PlatformHelper.ControlKey | KeyModifiers.Shift)
});

MainMenu.WatchTreeChanges(AddMenuItem, (r, p) => RemoveMenuItem(r));
Expand Down
29 changes: 29 additions & 0 deletions src/OneWare.Essentials/Commands/OpenSymbolApplicationCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Avalonia.LogicalTree;
using OneWare.Essentials.Services;
using OneWare.Essentials.ViewModels;

namespace OneWare.Essentials.Commands;

public class OpenSymbolApplicationCommand(string name, string file, int line, int character)
: ApplicationCommandBase(name)
{
public override bool Execute(ILogical source)
{
_ = OpenAsync();
return true;
}

public override bool CanExecute(ILogical source)
{
return File.Exists(file);
}

private async Task OpenAsync()
{
if (await ContainerLocator.Container.Resolve<IMainDockService>().OpenFileAsync(file) is not IEditor editor)
return;

var documentLine = editor.CurrentDocument.GetLineByNumber(Math.Min(line + 1, editor.CurrentDocument.LineCount));
editor.Select(Math.Min(documentLine.Offset + character, documentLine.EndOffset), 0);
}
}
5 changes: 3 additions & 2 deletions src/OneWare.Essentials/LanguageService/ILanguageService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using Newtonsoft.Json.Linq;
using OneWare.Essentials.EditorExtensions;
using OneWare.Essentials.ViewModels;
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
Expand Down Expand Up @@ -44,7 +45,7 @@ public interface ILanguageService
SignatureHelp? activeSignatureHelp);

public Task<CommandOrCodeActionContainer?> RequestCodeActionAsync(string fullPath, Range range,
Diagnostic diagnostic);
IEnumerable<Diagnostic>? diagnostics = null);

public Task<Container<FoldingRange>?> RequestFoldingsAsync(string fullPath);
public Task<Hover?> RequestHoverAsync(string fullPath, Position pos);
Expand All @@ -67,7 +68,7 @@ public interface ILanguageService
public Task<InlayHintContainer?> RequestInlayHintsAsync(string fullPath, Range range);
public Task<TextEditContainer?> RequestFormattingAsync(string fullPath);
public Task<TextEditContainer?> RequestRangeFormattingAsync(string fullPath, Range range);
public Task ExecuteCommandAsync(Command cmd);
public Task<JToken?> ExecuteCommandAsync(Command cmd);
public Task<ApplyWorkspaceEditResponse> ApplyWorkspaceEditAsync(ApplyWorkspaceEditParams param);
public Task ApplyWorkspaceEditAsync(WorkspaceEdit? param);
public void ApplyContainer(string path, IEnumerable<TextEdit> con);
Expand Down
14 changes: 10 additions & 4 deletions src/OneWare.Essentials/LanguageService/LanguageServiceBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia.Threading;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OneWare.Essentials.EditorExtensions;
using OneWare.Essentials.Enums;
Expand Down Expand Up @@ -96,7 +97,7 @@ public virtual void RefreshTextDocument(string fullPath, string newText)
}

public virtual Task<CommandOrCodeActionContainer?> RequestCodeActionAsync(string fullPath, Range range,
Diagnostic diagnostic)
IEnumerable<Diagnostic>? diagnostics = null)
{
return Task.FromResult<CommandOrCodeActionContainer?>(null);
}
Expand Down Expand Up @@ -176,9 +177,9 @@ public virtual void RefreshTextDocument(string fullPath, string newText)
return Task.FromResult<TextEditContainer?>(null);
}

public virtual Task ExecuteCommandAsync(Command cmd)
public virtual Task<JToken?> ExecuteCommandAsync(Command cmd)
{
return Task.CompletedTask;
return Task.FromResult<JToken?>(null);
}

public virtual async Task<ApplyWorkspaceEditResponse> ApplyWorkspaceEditAsync(ApplyWorkspaceEditParams param)
Expand Down Expand Up @@ -321,8 +322,13 @@ protected virtual IEnumerable<ErrorListItem> ConvertErrors(PublishDiagnosticsPar
_ => ErrorType.Hint
};

var endLine = p.Range.End.Line;
var endCharacter = p.Range.End.Character;
if (p.Range.Start.Line == endLine && p.Range.Start.Character == endCharacter)
endCharacter++;

yield return new ErrorListItem(p.Message, errorType, fullPath, Name, p.Range.Start.Line + 1,
p.Range.Start.Character + 1, p.Range.End.Line + 1, p.Range.End.Character + 1,
p.Range.Start.Character + 1, endLine + 1, endCharacter + 1,
p.Code?.String ?? p.Code?.Long.ToString() ?? "", p, root);
}
}
Expand Down
Loading
Loading