feat(lsp): initial support for textDocument/rename
flow keybinds: changes f2 from toggle_input_mode to rename_symbol and
moves toggle_input_mode command to ctrl+shift+f2 (since ctrl+f2 is
already bound to insert_command_name)
the replacement text is hard coded for now. i've checked that replace
works with zls and pylsp which send WorkspaceEdit response messages in
different shapes - zls sends shape `{"changes": {}}` while pylsp sends
`{"documentChanges": []}`.
currently the 'rename_symbol_item' commands are sent one at a time.
however they should be buffered and be performed between one
buf_for_update, update_buf pair.  this will be addressed in a follow up.
			
			
This commit is contained in:
		
							parent
							
								
									7558a63819
								
							
						
					
					
						commit
						1fd4455adb
					
				
					 5 changed files with 172 additions and 1 deletions
				
			
		|  | @ -176,6 +176,13 @@ pub fn completion(file_path: []const u8, row: usize, col: usize) (ProjectManager | |||
|     return send(.{ "completion", project, file_path, row, col }); | ||||
| } | ||||
| 
 | ||||
| pub fn rename_symbol(file_path: []const u8, row: usize, col: usize) (ProjectManagerError || ProjectError)!void { | ||||
|     const project = tp.env.get().str("project"); | ||||
|     if (project.len == 0) | ||||
|         return error.NoProject; | ||||
|     return send(.{ "rename_symbol", project, file_path, row, col }); | ||||
| } | ||||
| 
 | ||||
| pub fn hover(file_path: []const u8, row: usize, col: usize) (ProjectManagerError || ProjectError)!void { | ||||
|     const project = tp.env.get().str("project"); | ||||
|     if (project.len == 0) | ||||
|  | @ -339,6 +346,8 @@ const Process = struct { | |||
|             self.references(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed; | ||||
|         } else if (try cbor.match(m.buf, .{ "completion", tp.extract(&project_directory), tp.extract(&path), tp.extract(&row), tp.extract(&col) })) { | ||||
|             self.completion(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed; | ||||
|         } else if (try cbor.match(m.buf, .{ "rename_symbol", tp.extract(&project_directory), tp.extract(&path), tp.extract(&row), tp.extract(&col) })) { | ||||
|             self.rename_symbol(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed; | ||||
|         } else if (try cbor.match(m.buf, .{ "hover", tp.extract(&project_directory), tp.extract(&path), tp.extract(&row), tp.extract(&col) })) { | ||||
|             self.hover(from, project_directory, path, row, col) catch |e| return from.forward_error(e, @errorReturnTrace()) catch error.ClientFailed; | ||||
|         } else if (try cbor.match(m.buf, .{ "get_mru_position", tp.extract(&project_directory), tp.extract(&path) })) { | ||||
|  | @ -492,6 +501,13 @@ const Process = struct { | |||
|         return project.completion(from, file_path, row, col); | ||||
|     } | ||||
| 
 | ||||
|     fn rename_symbol(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) (ProjectError || Project.InvalidMessageError || Project.LspOrClientError || cbor.Error)!void { | ||||
|         const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".rename_symbol" }); | ||||
|         defer frame.deinit(); | ||||
|         const project = self.projects.get(project_directory) orelse return error.NoProject; | ||||
|         return project.rename_symbol(from, file_path, row, col); | ||||
|     } | ||||
| 
 | ||||
|     fn hover(self: *Process, from: tp.pid_ref, project_directory: []const u8, file_path: []const u8, row: usize, col: usize) (ProjectError || Project.InvalidMessageError || Project.LspOrClientError || cbor.Error)!void { | ||||
|         const frame = tracy.initZone(@src(), .{ .name = module_name ++ ".hover" }); | ||||
|         defer frame.deinit(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Travis Staloch
						Travis Staloch