@@ -3,33 +3,27 @@ const zls = @import("zls");
33const builtin = @import ("builtin" );
44const test_options = @import ("test_options" );
55
6- const Config = zls .Config ;
7- const Server = zls .Server ;
86const types = zls .lsp .types ;
97
108const allocator = std .testing .allocator ;
119
12- const default_config : Config = .{
10+ const default_config : zls.configuration.UnresolvedConfig = .{
1311 .semantic_tokens = .full ,
1412 .prefer_ast_check_as_child_process = false ,
1513 .inlay_hints_exclude_single_argument = false ,
1614 .inlay_hints_show_builtin = true ,
1715};
1816
1917pub const Context = struct {
20- server : * Server ,
18+ server : * zls. Server ,
2119 arena : std.heap.ArenaAllocator ,
2220 file_id : u32 = 0 ,
2321
24- var config_arena : std.heap.ArenaAllocator.State = .{};
25- var cached_config : ? Config = null ;
26- var cached_resolved_config : ? @FieldType (Server , "resolved_config" ) = null ;
22+ var cached_config_arena : std.heap.ArenaAllocator = .init (std .heap .page_allocator );
23+ var cached_config_manager : ? zls.configuration.Manager = null ;
2724
2825 pub fn init () ! Context {
29- const server = try Server .create (allocator );
30- errdefer server .destroy ();
31-
32- if (cached_config == null and cached_resolved_config == null ) {
26+ const config_manager = cached_config_manager orelse config_manager : {
3327 var config = default_config ;
3428 defer if (builtin .target .os .tag != .wasi ) {
3529 if (config .zig_exe_path ) | zig_exe_path | allocator .free (zig_exe_path );
@@ -44,19 +38,25 @@ pub const Context = struct {
4438 config .global_cache_path = try std .fs .path .resolve (allocator , &.{ cwd , test_options .global_cache_path });
4539 }
4640
47- try server . updateConfiguration2 ( config , .{ . leaky_config_arena = true }) ;
48- } else {
49- // the configuration has previously been resolved and cached.
50- server . config_arena = config_arena ;
51- server . config = cached_config .? ;
52- server . resolved_config = cached_resolved_config .? ;
41+ var config_manager : zls.configuration.Manager = .init ;
42+ try config_manager . setConfiguration ( cached_config_arena . allocator (), .frontend , & config );
43+ _ = try config_manager . resolveConfiguration ( cached_config_arena . allocator ());
44+ cached_config_manager = config_manager ;
45+ break : config_manager config_manager ;
46+ } ;
5347
54- try server .updateConfiguration2 (server .config , .{ .leaky_config_arena = true , .resolve = false });
55- }
48+ const server : * zls.Server = try .create (.{
49+ .allocator = allocator ,
50+ .transport = null ,
51+ .config = null ,
52+ .config_manager = config_manager ,
53+ });
54+ errdefer server .destroy ();
5655
57- std .debug .assert (server .resolved_config .zig_lib_dir != null );
56+ std .debug .assert (server .config_manager .zig_lib_dir != null );
5857 std .debug .assert (server .document_store .config .zig_lib_dir != null );
59- std .debug .assert (server .resolved_config .global_cache_dir != null );
58+
59+ std .debug .assert (server .config_manager .global_cache_dir != null );
6060 std .debug .assert (server .document_store .config .global_cache_dir != null );
6161
6262 var context : Context = .{
@@ -71,13 +71,7 @@ pub const Context = struct {
7171 }
7272
7373 pub fn deinit (self : * Context ) void {
74- config_arena = self .server .config_arena ;
75- cached_config = self .server .config ;
76- cached_resolved_config = self .server .resolved_config ;
77-
78- self .server .config_arena = .{};
79- self .server .config = .{};
80- self .server .resolved_config = .unresolved ;
74+ self .server .config_manager = .init ;
8175
8276 _ = self .server .sendRequestSync (self .arena .allocator (), "shutdown" , {}) catch unreachable ;
8377 self .server .sendNotificationSync (self .arena .allocator (), "exit" , {}) catch unreachable ;
0 commit comments