-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): improve jump to error when runing in vscode (#4012)
When opening a hyperlink in vs-code, the default behavior is to open the hyperlink in the currently focused 'Editor Group.' However, when we have the Console open side by side with the wing file, this default behavior causes vs-code to open the file as a new tab in the Console panel group (if the group where you have the Console is focused). This PR adds two new endpoints: `[POST] app.openFileInEditor` and `app.openFileInEditorSubscription` When clicking on an error link the Console emits an event named `openFileInEditor`. Code editors like vscode (and potentially others) can subscribe to the new sub endpoint to receive these events. Previous behaviour (using hyperlinks) https://github.com/winglang/wing/assets/5547636/305a58ef-1f90-499e-a72d-60a00cefe2ca New behaviour (using sub) https://github.com/winglang/wing/assets/5547636/ae9c5d84-c70a-4160-b019-7b9144509797 Weird case when you have 425924593 groups https://github.com/winglang/wing/assets/5547636/ec52da55-887d-4b46-84a2-8d0b566669b0 resolves #3337 *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
Showing
8 changed files
with
169 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { PropsWithChildren } from "react"; | ||
|
||
import { trpc } from "../services/trpc.js"; | ||
|
||
export const createHtmlLink = ( | ||
error: string, | ||
className: string, | ||
expanded: boolean = false, | ||
) => { | ||
return error | ||
.replaceAll( | ||
/\B((?:[a-z]:)?[/\\]\S+):(\d+):(\d+)/gi, | ||
(match, path, line, column) => { | ||
const link = `vscode://file/${path}:${line}:${column}`; | ||
return `<a class="${className}" href="${link}" path="${path}" line="${line}" column="${column}" >${match}</a>`; | ||
}, | ||
) | ||
.replaceAll(/(\r\n|\n|\r)/gm, expanded ? "<br />" : "\n"); | ||
}; | ||
|
||
export const OpenFileInEditorButton = ({ children }: PropsWithChildren) => { | ||
const openFileInEditor = trpc["app.openFileInEditor"].useMutation(); | ||
|
||
return ( | ||
<button | ||
className="appearance-none text-left" | ||
onClick={(event) => { | ||
const target = event.target as HTMLElement; | ||
if (target.tagName === "A") { | ||
const path = target.getAttribute("path")!; | ||
const line = target.getAttribute("line")!; | ||
const column = target.getAttribute("column")!; | ||
|
||
if (!path || !line || !column) { | ||
return; | ||
} | ||
|
||
openFileInEditor.mutate({ | ||
path, | ||
line: Number.parseInt(line), | ||
column: Number.parseInt(column), | ||
}); | ||
} | ||
}} | ||
> | ||
{children} | ||
</button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters