-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a terminal provider to detect the Java stacktrace printed in term…
…inal
- Loading branch information
1 parent
0755aa2
commit f3239ed
Showing
6 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,61 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
import { CancellationToken, commands, Position, ProviderResult, Range, TerminalLink, TerminalLinkContext, | ||
TerminalLinkProvider, Uri, window } from "vscode"; | ||
import { resolveSourceUri } from "./languageServerPlugin"; | ||
|
||
export class JavaTerminalLinkProvder implements TerminalLinkProvider<IJavaTerminalLink> { | ||
/** | ||
* Provide terminal links for the given context. Note that this can be called multiple times | ||
* even before previous calls resolve, make sure to not share global objects (eg. `RegExp`) | ||
* that could have problems when asynchronous usage may overlap. | ||
* @param context Information about what links are being provided for. | ||
* @param token A cancellation token. | ||
* @return A list of terminal links for the given line. | ||
*/ | ||
public provideTerminalLinks(context: TerminalLinkContext, token: CancellationToken): ProviderResult<IJavaTerminalLink[]> { | ||
if (context.terminal.name !== "Java Debug Console" && context.terminal.name !== "Java Process Console") { | ||
return []; | ||
} | ||
|
||
const regex = new RegExp("(\\sat\\s+)([\\w$\\.]+\\/)?(([\\w$]+\\.)+[<\\w$>]+)\\(([\\w-$]+\\.java:\\d+)\\)"); | ||
const result: RegExpExecArray = regex.exec(context.line); | ||
if (result && result.length) { | ||
const stackTrace = `${result[2] || ""}${result[3]}(${result[5]})`; | ||
const sourceLineNumber = Number(result[5].split(":")[1]); | ||
return [{ | ||
startIndex: result.index + result[1].length, | ||
length: stackTrace.length, | ||
methodName: result[3], | ||
stackTrace, | ||
lineNumber: sourceLineNumber, | ||
}]; | ||
} | ||
} | ||
|
||
/** | ||
* Handle an activated terminal link. | ||
*/ | ||
public async handleTerminalLink(link: IJavaTerminalLink): Promise<void> { | ||
const uri = await resolveSourceUri(link.stackTrace); | ||
if (uri) { | ||
const lineNumber = Math.max(link.lineNumber - 1, 0); | ||
window.showTextDocument(Uri.parse(uri), { | ||
preserveFocus: true, | ||
selection: new Range(new Position(lineNumber, 0), new Position(lineNumber, 0)), | ||
}); | ||
} else { | ||
// If no source is found, then open the searching symbols quickpick box. | ||
const fullyQualifiedName = link.methodName.substring(0, link.methodName.lastIndexOf(".")); | ||
const className = fullyQualifiedName.substring(fullyQualifiedName.lastIndexOf(".") + 1); | ||
commands.executeCommand("workbench.action.quickOpen", "#" + className); | ||
} | ||
} | ||
} | ||
|
||
interface IJavaTerminalLink extends TerminalLink { | ||
methodName: string; | ||
stackTrace: string; | ||
lineNumber: number; | ||
} |