Skip to content

Commit

Permalink
fix(typescript): correct new file edit conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 10, 2024
1 parent 811707e commit 4a333b8
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions packages/typescript/lib/utils/lspConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,17 +621,32 @@ export function convertFileTextChanges(
workspaceEdit.documentChanges = [];
}
const uri = fileNameToUri(change.fileName);
const doc = getTextDocument(uri);
if (change.isNewFile) {
workspaceEdit.documentChanges.push({ kind: 'create', uri });
workspaceEdit.documentChanges.push({
textDocument: {
uri,
version: null, // fix https://github.com/johnsoncodehk/volar/issues/2025
},
edits: change.textChanges.map(edit => ({
newText: edit.newText,
range: {
start: { line: 0, character: edit.span.start },
end: { line: 0, character: edit.span.start + edit.span.length },
},
})),
});
}
else {
const doc = getTextDocument(uri);
workspaceEdit.documentChanges.push({
textDocument: {
uri,
version: null, // fix https://github.com/johnsoncodehk/volar/issues/2025
},
edits: change.textChanges.map(edit => convertTextChange(edit, doc)),
});
}
workspaceEdit.documentChanges.push({
textDocument: {
uri,
version: null, // fix https://github.com/johnsoncodehk/volar/issues/2025
},
edits: change.textChanges.map(edit => convertTextChange(edit, doc)),
});
}
return workspaceEdit;
}
Expand Down

0 comments on commit 4a333b8

Please sign in to comment.