forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Launch Native REPL using terminal link (#24734)
Resolves: #24270 Perhaps further improve via #24270 (comment) ?
- Loading branch information
1 parent
92cc4ed
commit 25411e5
Showing
7 changed files
with
151 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* eslint-disable class-methods-use-this */ | ||
import { | ||
CancellationToken, | ||
Disposable, | ||
ProviderResult, | ||
TerminalLink, | ||
TerminalLinkContext, | ||
TerminalLinkProvider, | ||
} from 'vscode'; | ||
import { executeCommand } from '../common/vscodeApis/commandApis'; | ||
import { registerTerminalLinkProvider } from '../common/vscodeApis/windowApis'; | ||
import { Repl } from '../common/utils/localize'; | ||
|
||
interface CustomTerminalLink extends TerminalLink { | ||
command: string; | ||
} | ||
|
||
export class CustomTerminalLinkProvider implements TerminalLinkProvider<CustomTerminalLink> { | ||
provideTerminalLinks( | ||
context: TerminalLinkContext, | ||
_token: CancellationToken, | ||
): ProviderResult<CustomTerminalLink[]> { | ||
const links: CustomTerminalLink[] = []; | ||
const expectedNativeLink = 'VS Code Native REPL'; | ||
|
||
if (context.line.includes(expectedNativeLink)) { | ||
links.push({ | ||
startIndex: context.line.indexOf(expectedNativeLink), | ||
length: expectedNativeLink.length, | ||
tooltip: Repl.launchNativeRepl, | ||
command: 'python.startNativeREPL', | ||
}); | ||
} | ||
return links; | ||
} | ||
|
||
async handleTerminalLink(link: CustomTerminalLink): Promise<void> { | ||
await executeCommand(link.command); | ||
} | ||
} | ||
|
||
export function registerCustomTerminalLinkProvider(disposables: Disposable[]): void { | ||
disposables.push(registerTerminalLinkProvider(new CustomTerminalLinkProvider())); | ||
} |
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