@@ -11,7 +11,10 @@ import (
13func applyTextEdits(uri protocol.DocumentURI, edits []protocol.TextEdit) error {
13func applyTextEdits(uri protocol.DocumentURI, edits []protocol.TextEdit) error {
14− path := uri.Path()
14+ path, err := uri.Path()
16+ return fmt.Errorf("invalid URI: %w", err)
16 // Read the file content
19 // Read the file content
17 content, err := os.ReadFile(path)
20 content, err := os.ReadFile(path)
@@ -148,7 +151,11 @@ func applyTextEdit(lines []string, edit protocol.TextEdit) ([]string, error) {
148// applyDocumentChange applies a DocumentChange (create/rename/delete operations)
151// applyDocumentChange applies a DocumentChange (create/rename/delete operations)
149func applyDocumentChange(change protocol.DocumentChange) error {
152func applyDocumentChange(change protocol.DocumentChange) error {
150 if change.CreateFile != nil {
153 if change.CreateFile != nil {
151− path := change.CreateFile.URI.Path()
154+ path, err := change.CreateFile.URI.Path()
156+ return fmt.Errorf("invalid URI: %w", err)
152 if change.CreateFile.Options != nil {
159 if change.CreateFile.Options != nil {
153 if change.CreateFile.Options.Overwrite {
160 if change.CreateFile.Options.Overwrite {
154 // Proceed with overwrite
161 // Proceed with overwrite
@@ -164,7 +171,11 @@ func applyDocumentChange(change protocol.DocumentChange) error {
166 if change.DeleteFile != nil {
173 if change.DeleteFile != nil {
167− path := change.DeleteFile.URI.Path()
174+ path, err := change.DeleteFile.URI.Path()
176+ return fmt.Errorf("invalid URI: %w", err)
168 if change.DeleteFile.Options != nil && change.DeleteFile.Options.Recursive {
179 if change.DeleteFile.Options != nil && change.DeleteFile.Options.Recursive {
169 if err := os.RemoveAll(path); err != nil {
180 if err := os.RemoveAll(path); err != nil {
170 return fmt.Errorf("failed to delete directory recursively: %w", err)
181 return fmt.Errorf("failed to delete directory recursively: %w", err)
@@ -177,8 +188,19 @@ func applyDocumentChange(change protocol.DocumentChange) error {
179 if change.RenameFile != nil {
190 if change.RenameFile != nil {
191+ var newPath, oldPath string
180− oldPath := change.RenameFile.OldURI.Path()
194+ oldPath, err = change.RenameFile.OldURI.Path()
181− newPath := change.RenameFile.NewURI.Path()
199+ newPath, err = change.RenameFile.NewURI.Path()
182 if change.RenameFile.Options != nil {
204 if change.RenameFile.Options != nil {
183 if !change.RenameFile.Options.Overwrite {
205 if !change.RenameFile.Options.Overwrite {
184 if _, err := os.Stat(newPath); err == nil {
206 if _, err := os.Stat(newPath); err == nil {