commit
6e018d035e
@ -94,6 +94,31 @@ pub fn getFunctionSignature(tree: Ast, func: Ast.full.FnProto) []const u8 {
|
|||||||
return tree.source[start.start..end.end];
|
return tree.source[start.start..end.end];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn formatSnippetPlaceholder(
|
||||||
|
data: []const u8,
|
||||||
|
comptime fmt: []const u8,
|
||||||
|
options: std.fmt.FormatOptions,
|
||||||
|
writer: anytype,
|
||||||
|
) !void {
|
||||||
|
_ = fmt;
|
||||||
|
_ = options;
|
||||||
|
|
||||||
|
var splitit = std.mem.split(u8, data, "}");
|
||||||
|
while (splitit.next()) |segment| {
|
||||||
|
try writer.writeAll(segment);
|
||||||
|
if (splitit.index) |index|
|
||||||
|
if (data[index - 1] == '}') {
|
||||||
|
try writer.writeAll("\\}");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const SnippetPlaceholderFormatter = std.fmt.Formatter(formatSnippetPlaceholder);
|
||||||
|
|
||||||
|
fn fmtSnippetPlaceholder(bytes: []const u8) SnippetPlaceholderFormatter {
|
||||||
|
return .{ .data = bytes };
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates snippet insert text for a function. Caller owns returned memory.
|
/// Creates snippet insert text for a function. Caller owns returned memory.
|
||||||
pub fn getFunctionSnippet(allocator: std.mem.Allocator, tree: Ast, func: Ast.full.FnProto, skip_self_param: bool) ![]const u8 {
|
pub fn getFunctionSnippet(allocator: std.mem.Allocator, tree: Ast, func: Ast.full.FnProto, skip_self_param: bool) ![]const u8 {
|
||||||
const name_index = func.name_token.?;
|
const name_index = func.name_token.?;
|
||||||
@ -127,7 +152,7 @@ pub fn getFunctionSnippet(allocator: std.mem.Allocator, tree: Ast, func: Ast.ful
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (param.name_token) |name_token| {
|
if (param.name_token) |name_token| {
|
||||||
try buffer.appendSlice(tree.tokenSlice(name_token));
|
try buf_stream.print("{}", .{fmtSnippetPlaceholder(tree.tokenSlice(name_token))});
|
||||||
try buffer.appendSlice(": ");
|
try buffer.appendSlice(": ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +169,7 @@ pub fn getFunctionSnippet(allocator: std.mem.Allocator, tree: Ast, func: Ast.ful
|
|||||||
const is_comma = tag == .comma;
|
const is_comma = tag == .comma;
|
||||||
|
|
||||||
if (curr_token == end_token and is_comma) continue;
|
if (curr_token == end_token and is_comma) continue;
|
||||||
try buffer.appendSlice(tree.tokenSlice(curr_token));
|
try buf_stream.print("{}", .{fmtSnippetPlaceholder(tree.tokenSlice(curr_token))});
|
||||||
if (is_comma or tag == .keyword_const) try buffer.append(' ');
|
if (is_comma or tag == .keyword_const) try buffer.append(' ');
|
||||||
}
|
}
|
||||||
} else unreachable;
|
} else unreachable;
|
||||||
|
@ -1787,7 +1787,6 @@ fn requestConfiguration(arena: *std.heap.ArenaAllocator) !void {
|
|||||||
var comp_confi: [std.meta.fields(Config).len]types.ConfigurationParams.ConfigurationItem = undefined;
|
var comp_confi: [std.meta.fields(Config).len]types.ConfigurationParams.ConfigurationItem = undefined;
|
||||||
inline for (std.meta.fields(Config)) |field, index| {
|
inline for (std.meta.fields(Config)) |field, index| {
|
||||||
comp_confi[index] = .{
|
comp_confi[index] = .{
|
||||||
.scopeUri = "zls",
|
|
||||||
.section = "zls." ++ field.name,
|
.section = "zls." ++ field.name,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -2189,7 +2188,7 @@ fn didChangeConfigurationHandler(arena: *std.heap.ArenaAllocator, id: types.Requ
|
|||||||
inline for (std.meta.fields(Config)) |field| {
|
inline for (std.meta.fields(Config)) |field| {
|
||||||
if (@field(req.params.settings, field.name)) |value| {
|
if (@field(req.params.settings, field.name)) |value| {
|
||||||
logger.debug("setting configuration option '{s}' to '{any}'", .{ field.name, value });
|
logger.debug("setting configuration option '{s}' to '{any}'", .{ field.name, value });
|
||||||
@field(config, field.name) = value;
|
@field(config, field.name) = if (@TypeOf(value) == []const u8) try gpa_state.allocator().dupe(u8, value) else value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (client_capabilities.supports_configuration)
|
} else if (client_capabilities.supports_configuration)
|
||||||
@ -2262,7 +2261,7 @@ fn processJsonRpc(arena: *std.heap.ArenaAllocator, parser: *std.json.Parser, jso
|
|||||||
if (value != .Null) {
|
if (value != .Null) {
|
||||||
const new_value: field.field_type = switch (ft) {
|
const new_value: field.field_type = switch (ft) {
|
||||||
[]const u8 => switch (value) {
|
[]const u8 => switch (value) {
|
||||||
.String => |s| s,
|
.String => |s| try gpa_state.allocator().dupe(u8, s), // TODO: Allocation model? (same with didChangeConfiguration); imo this isn't *that* bad but still
|
||||||
else => @panic("Invalid configuration value"), // TODO: Handle this
|
else => @panic("Invalid configuration value"), // TODO: Handle this
|
||||||
},
|
},
|
||||||
else => switch (ti) {
|
else => switch (ti) {
|
||||||
|
@ -398,7 +398,6 @@ pub const ConfigurationParams = struct {
|
|||||||
items: []const ConfigurationItem,
|
items: []const ConfigurationItem,
|
||||||
|
|
||||||
pub const ConfigurationItem = struct {
|
pub const ConfigurationItem = struct {
|
||||||
scopeUri: ?[]const u8,
|
|
||||||
section: ?[]const u8,
|
section: ?[]const u8,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user