Skip to content

Commit

Permalink
Improve how renamed state keys are printed (#465)
Browse files Browse the repository at this point in the history
* Improve how renamed state keys are printed

* Implement initial state edits (#466)

* Implement initial state edits

* Implement initial state insertions before existing states property (#467)
  • Loading branch information
Andarist authored Feb 13, 2024
1 parent ab4d742 commit 321088d
Show file tree
Hide file tree
Showing 12 changed files with 1,303 additions and 59 deletions.
23 changes: 19 additions & 4 deletions new-packages/language-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,26 @@ connection.onRequest(applyPatches, async ({ uri, machineIndex, patches }) => {
patches,
});

return edits.map(({ fileName, range, ...rest }) => {
return edits.map((edit) => {
if (edit.type === 'replace') {
return {
type: 'replace' as const,
uri: server.env.fileNameToUri(edit.fileName),
range: xstateProject.getLinesAndCharactersRange(
edit.fileName,
edit.range,
),
newText: edit.newText,
};
}
return {
...rest,
uri: server.env.fileNameToUri(fileName),
range: xstateProject.getLinesAndCharactersRange(fileName, range),
type: edit.type,
uri: server.env.fileNameToUri(edit.fileName),
position: xstateProject.getLineAndCharacterOfPosition(
edit.fileName,
edit.position,
),
newText: edit.newText,
};
});
});
Expand Down
25 changes: 14 additions & 11 deletions new-packages/language-server/src/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import type {
ExtractorDigraphDef,
LineAndCharacterPosition,
LinesAndCharactersRange,
Patch,
} from '@xstate/ts-project';
import * as vscode from 'vscode-languageserver-protocol';

type DistributiveOmit<T, K extends PropertyKey> = T extends unknown
? Omit<T, K>
: never;

type TextEdit = DistributiveOmit<
import('@xstate/ts-project').TextEdit,
'fileName' | 'range'
> & {
uri: string;
range: LinesAndCharactersRange;
};
type TextEdit =
| {
type: 'insert';
uri: string;
position: LineAndCharacterPosition;
newText: string;
}
| {
type: 'replace';
uri: string;
range: LinesAndCharactersRange;
newText: string;
};

export const getMachineAtIndex = new vscode.RequestType<
{
Expand Down
Loading

0 comments on commit 321088d

Please sign in to comment.