refactor: move LSP types to new module
This commit is contained in:
parent
e5894c1404
commit
308f46c8a2
5 changed files with 136 additions and 162 deletions
|
|
@ -418,6 +418,10 @@ pub fn build_exe(
|
||||||
.root_source_file = b.path("src/snippet.zig"),
|
.root_source_file = b.path("src/snippet.zig"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const lsp_types_mod = b.createModule(.{
|
||||||
|
.root_source_file = b.path("src/lsp_types.zig"),
|
||||||
|
});
|
||||||
|
|
||||||
const Buffer_mod = b.createModule(.{
|
const Buffer_mod = b.createModule(.{
|
||||||
.root_source_file = b.path("src/buffer/Buffer.zig"),
|
.root_source_file = b.path("src/buffer/Buffer.zig"),
|
||||||
.imports = &.{
|
.imports = &.{
|
||||||
|
|
@ -635,6 +639,7 @@ pub fn build_exe(
|
||||||
.{ .name = "VcsStatus", .module = VcsStatus_mod },
|
.{ .name = "VcsStatus", .module = VcsStatus_mod },
|
||||||
.{ .name = "bin_path", .module = bin_path_mod },
|
.{ .name = "bin_path", .module = bin_path_mod },
|
||||||
.{ .name = "snippet", .module = snippet_mod },
|
.{ .name = "snippet", .module = snippet_mod },
|
||||||
|
.{ .name = "lsp_types", .module = lsp_types_mod },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
28
src/LSP.zig
28
src/LSP.zig
|
|
@ -735,31 +735,3 @@ const Headers = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const CompletionItemKind = enum(u8) {
|
|
||||||
Text = 1,
|
|
||||||
Method = 2,
|
|
||||||
Function = 3,
|
|
||||||
Constructor = 4,
|
|
||||||
Field = 5,
|
|
||||||
Variable = 6,
|
|
||||||
Class = 7,
|
|
||||||
Interface = 8,
|
|
||||||
Module = 9,
|
|
||||||
Property = 10,
|
|
||||||
Unit = 11,
|
|
||||||
Value = 12,
|
|
||||||
Enum = 13,
|
|
||||||
Keyword = 14,
|
|
||||||
Snippet = 15,
|
|
||||||
Color = 16,
|
|
||||||
File = 17,
|
|
||||||
Reference = 18,
|
|
||||||
Folder = 19,
|
|
||||||
EnumMember = 20,
|
|
||||||
Constant = 21,
|
|
||||||
Struct = 22,
|
|
||||||
Event = 23,
|
|
||||||
Operator = 24,
|
|
||||||
TypeParameter = 25,
|
|
||||||
};
|
|
||||||
|
|
|
||||||
121
src/lsp_types.zig
Normal file
121
src/lsp_types.zig
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
pub const SymbolKind = enum(u8) {
|
||||||
|
None = 0,
|
||||||
|
File = 1,
|
||||||
|
Module = 2,
|
||||||
|
Namespace = 3,
|
||||||
|
Package = 4,
|
||||||
|
Class = 5,
|
||||||
|
Method = 6,
|
||||||
|
Property = 7,
|
||||||
|
Field = 8,
|
||||||
|
Constructor = 9,
|
||||||
|
Enum = 10,
|
||||||
|
Interface = 11,
|
||||||
|
Function = 12,
|
||||||
|
Variable = 13,
|
||||||
|
Constant = 14,
|
||||||
|
String = 15,
|
||||||
|
Number = 16,
|
||||||
|
Boolean = 17,
|
||||||
|
Array = 18,
|
||||||
|
Object = 19,
|
||||||
|
Key = 20,
|
||||||
|
Null = 21,
|
||||||
|
EnumMember = 22,
|
||||||
|
Struct = 23,
|
||||||
|
Event = 24,
|
||||||
|
Operator = 25,
|
||||||
|
TypeParameter = 26,
|
||||||
|
|
||||||
|
pub fn icon(kind: SymbolKind) []const u8 {
|
||||||
|
return switch (kind) {
|
||||||
|
.None => " ",
|
||||||
|
.File => "",
|
||||||
|
.Module => "",
|
||||||
|
.Namespace => "",
|
||||||
|
.Package => "",
|
||||||
|
.Class => "",
|
||||||
|
.Method => "",
|
||||||
|
.Property => "",
|
||||||
|
.Field => "",
|
||||||
|
.Constructor => "",
|
||||||
|
.Enum => "",
|
||||||
|
.Interface => "",
|
||||||
|
.Function => "",
|
||||||
|
.Variable => "",
|
||||||
|
.Constant => "",
|
||||||
|
.String => "",
|
||||||
|
.Number => "",
|
||||||
|
.Boolean => "",
|
||||||
|
.Array => "",
|
||||||
|
.Object => "",
|
||||||
|
.Key => "",
|
||||||
|
.Null => "",
|
||||||
|
.EnumMember => "",
|
||||||
|
.Struct => "",
|
||||||
|
.Event => "",
|
||||||
|
.Operator => "",
|
||||||
|
.TypeParameter => "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const CompletionItemKind = enum(u8) {
|
||||||
|
None = 0,
|
||||||
|
Text = 1,
|
||||||
|
Method = 2,
|
||||||
|
Function = 3,
|
||||||
|
Constructor = 4,
|
||||||
|
Field = 5,
|
||||||
|
Variable = 6,
|
||||||
|
Class = 7,
|
||||||
|
Interface = 8,
|
||||||
|
Module = 9,
|
||||||
|
Property = 10,
|
||||||
|
Unit = 11,
|
||||||
|
Value = 12,
|
||||||
|
Enum = 13,
|
||||||
|
Keyword = 14,
|
||||||
|
Snippet = 15,
|
||||||
|
Color = 16,
|
||||||
|
File = 17,
|
||||||
|
Reference = 18,
|
||||||
|
Folder = 19,
|
||||||
|
EnumMember = 20,
|
||||||
|
Constant = 21,
|
||||||
|
Struct = 22,
|
||||||
|
Event = 23,
|
||||||
|
Operator = 24,
|
||||||
|
TypeParameter = 25,
|
||||||
|
|
||||||
|
pub fn icon(kind: CompletionItemKind) []const u8 {
|
||||||
|
return switch (kind) {
|
||||||
|
.None => " ",
|
||||||
|
.Text => "",
|
||||||
|
.Method => "",
|
||||||
|
.Function => "",
|
||||||
|
.Constructor => "",
|
||||||
|
.Field => "",
|
||||||
|
.Variable => "",
|
||||||
|
.Class => "",
|
||||||
|
.Interface => "",
|
||||||
|
.Module => "",
|
||||||
|
.Property => "",
|
||||||
|
.Unit => "",
|
||||||
|
.Value => "",
|
||||||
|
.Enum => "",
|
||||||
|
.Keyword => "",
|
||||||
|
.Snippet => "",
|
||||||
|
.Color => "",
|
||||||
|
.File => "",
|
||||||
|
.Reference => "※",
|
||||||
|
.Folder => "🗀",
|
||||||
|
.EnumMember => "",
|
||||||
|
.Constant => "",
|
||||||
|
.Struct => "",
|
||||||
|
.Event => "",
|
||||||
|
.Operator => "",
|
||||||
|
.TypeParameter => "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -5,6 +5,7 @@ const root = @import("soft_root").root;
|
||||||
const command = @import("command");
|
const command = @import("command");
|
||||||
const Buffer = @import("Buffer");
|
const Buffer = @import("Buffer");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
const CompletionItemKind = @import("lsp_types").CompletionItemKind;
|
||||||
|
|
||||||
const tui = @import("../../tui.zig");
|
const tui = @import("../../tui.zig");
|
||||||
pub const Type = @import("palette.zig").Create(@This());
|
pub const Type = @import("palette.zig").Create(@This());
|
||||||
|
|
@ -104,7 +105,7 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T
|
||||||
if (!(cbor.matchValue(&iter, cbor.extract_cbor(&matches_cbor)) catch false)) return false;
|
if (!(cbor.matchValue(&iter, cbor.extract_cbor(&matches_cbor)) catch false)) return false;
|
||||||
|
|
||||||
const values = get_values(item_cbor);
|
const values = get_values(item_cbor);
|
||||||
const icon_: []const u8 = kind_icon(@enumFromInt(values.kind));
|
const icon_: []const u8 = values.kind.icon();
|
||||||
const color: u24 = 0x0;
|
const color: u24 = 0x0;
|
||||||
|
|
||||||
return tui.render_symbol(
|
return tui.render_symbol(
|
||||||
|
|
@ -125,7 +126,7 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T
|
||||||
const Values = struct {
|
const Values = struct {
|
||||||
label: []const u8,
|
label: []const u8,
|
||||||
sort_text: []const u8,
|
sort_text: []const u8,
|
||||||
kind: u8,
|
kind: CompletionItemKind,
|
||||||
replace: Buffer.Selection,
|
replace: Buffer.Selection,
|
||||||
additionalTextEdits: []const u8,
|
additionalTextEdits: []const u8,
|
||||||
label_detail: []const u8,
|
label_detail: []const u8,
|
||||||
|
|
@ -179,7 +180,7 @@ fn get_values(item_cbor: []const u8) Values {
|
||||||
return .{
|
return .{
|
||||||
.label = label_,
|
.label = label_,
|
||||||
.sort_text = sort_text,
|
.sort_text = sort_text,
|
||||||
.kind = kind,
|
.kind = @enumFromInt(kind),
|
||||||
.replace = replace,
|
.replace = replace,
|
||||||
.additionalTextEdits = additionalTextEdits,
|
.additionalTextEdits = additionalTextEdits,
|
||||||
.label_detail = label_detail,
|
.label_detail = label_detail,
|
||||||
|
|
@ -253,63 +254,3 @@ pub fn cancel(palette: *Type) !void {
|
||||||
const mv = tui.mainview() orelse return;
|
const mv = tui.mainview() orelse return;
|
||||||
mv.cancel_info_content() catch {};
|
mv.cancel_info_content() catch {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const CompletionItemKind = enum(u8) {
|
|
||||||
None = 0,
|
|
||||||
Text = 1,
|
|
||||||
Method = 2,
|
|
||||||
Function = 3,
|
|
||||||
Constructor = 4,
|
|
||||||
Field = 5,
|
|
||||||
Variable = 6,
|
|
||||||
Class = 7,
|
|
||||||
Interface = 8,
|
|
||||||
Module = 9,
|
|
||||||
Property = 10,
|
|
||||||
Unit = 11,
|
|
||||||
Value = 12,
|
|
||||||
Enum = 13,
|
|
||||||
Keyword = 14,
|
|
||||||
Snippet = 15,
|
|
||||||
Color = 16,
|
|
||||||
File = 17,
|
|
||||||
Reference = 18,
|
|
||||||
Folder = 19,
|
|
||||||
EnumMember = 20,
|
|
||||||
Constant = 21,
|
|
||||||
Struct = 22,
|
|
||||||
Event = 23,
|
|
||||||
Operator = 24,
|
|
||||||
TypeParameter = 25,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn kind_icon(kind: CompletionItemKind) []const u8 {
|
|
||||||
return switch (kind) {
|
|
||||||
.None => " ",
|
|
||||||
.Text => "",
|
|
||||||
.Method => "",
|
|
||||||
.Function => "",
|
|
||||||
.Constructor => "",
|
|
||||||
.Field => "",
|
|
||||||
.Variable => "",
|
|
||||||
.Class => "",
|
|
||||||
.Interface => "",
|
|
||||||
.Module => "",
|
|
||||||
.Property => "",
|
|
||||||
.Unit => "",
|
|
||||||
.Value => "",
|
|
||||||
.Enum => "",
|
|
||||||
.Keyword => "",
|
|
||||||
.Snippet => "",
|
|
||||||
.Color => "",
|
|
||||||
.File => "",
|
|
||||||
.Reference => "※",
|
|
||||||
.Folder => "🗀",
|
|
||||||
.EnumMember => "",
|
|
||||||
.Constant => "",
|
|
||||||
.Struct => "",
|
|
||||||
.Event => "",
|
|
||||||
.Operator => "",
|
|
||||||
.TypeParameter => "",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ const write_string = text_manip.write_string;
|
||||||
const write_padding = text_manip.write_padding;
|
const write_padding = text_manip.write_padding;
|
||||||
const command = @import("command");
|
const command = @import("command");
|
||||||
const Buffer = @import("Buffer");
|
const Buffer = @import("Buffer");
|
||||||
|
const SymbolKind = @import("lsp_types").SymbolKind;
|
||||||
|
|
||||||
const tui = @import("../../tui.zig");
|
const tui = @import("../../tui.zig");
|
||||||
pub const Type = @import("palette.zig").Create(@This());
|
pub const Type = @import("palette.zig").Create(@This());
|
||||||
|
|
@ -109,7 +110,7 @@ pub fn load_entries(palette: *Type) !usize {
|
||||||
const label_, const parent_, const kind, const sel = get_values(cbor_item);
|
const label_, const parent_, const kind, const sel = get_values(cbor_item);
|
||||||
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = label_[0..@min(columns[0].max_width, label_.len)], .range = sel };
|
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = label_[0..@min(columns[0].max_width, label_.len)], .range = sel };
|
||||||
|
|
||||||
const current_lengths: [3]usize = .{ label_.len, parent_.len, kind_name(@enumFromInt(kind)).len };
|
const current_lengths: [3]usize = .{ label_.len, parent_.len, @tagName(kind).len };
|
||||||
const label_len: u8 = @truncate(if (label_.len > columns[0].max_width) columns[0].max_width else label_.len);
|
const label_len: u8 = @truncate(if (label_.len > columns[0].max_width) columns[0].max_width else label_.len);
|
||||||
max_cols_len = @max(max_cols_len, label_len, update_max_col_sizes(palette, ¤t_lengths));
|
max_cols_len = @max(max_cols_len, label_len, update_max_col_sizes(palette, ¤t_lengths));
|
||||||
max_label_len = @max(max_label_len, label_len);
|
max_label_len = @max(max_label_len, label_len);
|
||||||
|
|
@ -153,19 +154,19 @@ pub fn on_render_menu(palette: *Type, button: *Type.ButtonType, theme: *const Wi
|
||||||
if (!(cbor.matchValue(&iter, cbor.extract_cbor(&matches_cbor)) catch false)) return false;
|
if (!(cbor.matchValue(&iter, cbor.extract_cbor(&matches_cbor)) catch false)) return false;
|
||||||
|
|
||||||
const label_, const container, const kind, _ = get_values(item_cbor);
|
const label_, const container, const kind, _ = get_values(item_cbor);
|
||||||
const icon_: []const u8 = kind_icon(@enumFromInt(kind));
|
const icon_: []const u8 = kind.icon();
|
||||||
const color: u24 = 0x0;
|
const color: u24 = 0x0;
|
||||||
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||||
defer value.deinit();
|
defer value.deinit();
|
||||||
const writer = &value.writer;
|
const writer = &value.writer;
|
||||||
var column_info = [_][]const u8{ label_, container, kind_name(@enumFromInt(kind)) };
|
var column_info = [_][]const u8{ label_, container, @tagName(kind) };
|
||||||
write_columns(palette, writer, &column_info);
|
write_columns(palette, writer, &column_info);
|
||||||
const indicator: []const u8 = &.{};
|
const indicator: []const u8 = &.{};
|
||||||
|
|
||||||
return tui.render_file_item(&button.plane, value.written(), icon_, color, indicator, &.{}, matches_cbor, button.active, selected, button.hover, theme);
|
return tui.render_file_item(&button.plane, value.written(), icon_, color, indicator, &.{}, matches_cbor, button.active, selected, button.hover, theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, u8, ed.Selection } {
|
fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, SymbolKind, ed.Selection } {
|
||||||
var label_: []const u8 = "";
|
var label_: []const u8 = "";
|
||||||
var container: []const u8 = "";
|
var container: []const u8 = "";
|
||||||
var kind: u8 = 0;
|
var kind: u8 = 0;
|
||||||
|
|
@ -187,7 +188,7 @@ fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, u8, ed.Sel
|
||||||
cbor.any, // deprecated
|
cbor.any, // deprecated
|
||||||
cbor.any, // detail
|
cbor.any, // detail
|
||||||
}) catch false;
|
}) catch false;
|
||||||
return .{ label_, container, kind, range };
|
return .{ label_, container, @enumFromInt(kind), range };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_closest(palette: *Type) ?usize {
|
fn find_closest(palette: *Type) ?usize {
|
||||||
|
|
@ -221,69 +222,3 @@ pub fn cancel(palette: *Type) !void {
|
||||||
editor.clear_matches();
|
editor.clear_matches();
|
||||||
editor.update_scroll_dest_abs(palette.value.view.row);
|
editor.update_scroll_dest_abs(palette.value.view.row);
|
||||||
}
|
}
|
||||||
|
|
||||||
const SymbolKind = enum(u8) {
|
|
||||||
None = 0,
|
|
||||||
File = 1,
|
|
||||||
Module = 2,
|
|
||||||
Namespace = 3,
|
|
||||||
Package = 4,
|
|
||||||
Class = 5,
|
|
||||||
Method = 6,
|
|
||||||
Property = 7,
|
|
||||||
Field = 8,
|
|
||||||
Constructor = 9,
|
|
||||||
Enum = 10,
|
|
||||||
Interface = 11,
|
|
||||||
Function = 12,
|
|
||||||
Variable = 13,
|
|
||||||
Constant = 14,
|
|
||||||
String = 15,
|
|
||||||
Number = 16,
|
|
||||||
Boolean = 17,
|
|
||||||
Array = 18,
|
|
||||||
Object = 19,
|
|
||||||
Key = 20,
|
|
||||||
Null = 21,
|
|
||||||
EnumMember = 22,
|
|
||||||
Struct = 23,
|
|
||||||
Event = 24,
|
|
||||||
Operator = 25,
|
|
||||||
TypeParameter = 26,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn kind_icon(kind: SymbolKind) []const u8 {
|
|
||||||
return switch (kind) {
|
|
||||||
.None => " ",
|
|
||||||
.File => "",
|
|
||||||
.Module => "",
|
|
||||||
.Namespace => "",
|
|
||||||
.Package => "",
|
|
||||||
.Class => "",
|
|
||||||
.Method => "",
|
|
||||||
.Property => "",
|
|
||||||
.Field => "",
|
|
||||||
.Constructor => "",
|
|
||||||
.Enum => "",
|
|
||||||
.Interface => "",
|
|
||||||
.Function => "",
|
|
||||||
.Variable => "",
|
|
||||||
.Constant => "",
|
|
||||||
.String => "",
|
|
||||||
.Number => "",
|
|
||||||
.Boolean => "",
|
|
||||||
.Array => "",
|
|
||||||
.Object => "",
|
|
||||||
.Key => "",
|
|
||||||
.Null => "",
|
|
||||||
.EnumMember => "",
|
|
||||||
.Struct => "",
|
|
||||||
.Event => "",
|
|
||||||
.Operator => "",
|
|
||||||
.TypeParameter => "",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn kind_name(kind: SymbolKind) []const u8 {
|
|
||||||
return @tagName(kind);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue