@@ -2,7 +2,8 @@ import * as vscode from "vscode";
2
2
import WebSocket = require( "ws" ) ;
3
3
4
4
import { AtelierAPI } from "../api" ;
5
- import { currentFile , outputChannel } from "../utils" ;
5
+ import { connectionTarget , currentFile , outputChannel } from "../utils" ;
6
+ import { config , resolveConnectionSpec } from "../extension" ;
6
7
7
8
const keys = {
8
9
enter : "\r" ,
@@ -596,6 +597,7 @@ class WebSocketTerminal implements vscode.Pseudoterminal {
596
597
function terminalConfigForUri (
597
598
api : AtelierAPI ,
598
599
extensionUri : vscode . Uri ,
600
+ targetUri : vscode . Uri ,
599
601
throwErrors = false
600
602
) : vscode . ExtensionTerminalOptions | undefined {
601
603
const reportError = ( msg : string ) => {
@@ -619,19 +621,60 @@ function terminalConfigForUri(
619
621
620
622
return {
621
623
name : api . config . serverName && api . config . serverName != "" ? api . config . serverName : "iris" ,
622
- location : vscode . TerminalLocation . Panel ,
624
+ location :
625
+ // Mimic what a built-in profile does. When it is the default and the Terminal tab is selected while empty,
626
+ // an terminal is always created in the Panel.
627
+ vscode . workspace . getConfiguration ( "terminal.integrated" , targetUri ) . get ( "defaultLocation" ) === "editor" &&
628
+ vscode . window . terminals . length > 0
629
+ ? vscode . TerminalLocation . Editor
630
+ : vscode . TerminalLocation . Panel ,
623
631
pty : new WebSocketTerminal ( api ) ,
624
632
isTransient : true ,
625
633
iconPath : vscode . Uri . joinPath ( extensionUri , "images" , "fileIcon.svg" ) ,
626
634
} ;
627
635
}
628
636
629
- export async function launchWebSocketTerminal ( extensionUri : vscode . Uri ) : Promise < void > {
637
+ async function workspaceUriForTerminal ( ) {
638
+ let uri : vscode . Uri ;
639
+ const workspaceFolders = vscode . workspace . workspaceFolders || [ ] ;
640
+ if ( workspaceFolders . length == 0 ) {
641
+ throw new Error ( "WebSocket Terminal requires an open workspace." ) ;
642
+ } else if ( workspaceFolders . length == 1 ) {
643
+ // Use the current connection
644
+ uri = workspaceFolders [ 0 ] . uri ;
645
+ } else {
646
+ // Pick from the workspace folders
647
+ uri = (
648
+ await vscode . window . showWorkspaceFolderPick ( {
649
+ ignoreFocusOut : true ,
650
+ placeHolder : "Pick the workspace folder to get server connection information from" ,
651
+ } )
652
+ ) ?. uri ;
653
+ }
654
+ return uri ;
655
+ }
656
+
657
+ export async function launchWebSocketTerminal ( extensionUri : vscode . Uri , targetUri ?: vscode . Uri ) : Promise < void > {
630
658
// Determine the server to connect to
631
- const api = new AtelierAPI ( currentFile ( ) ?. uri ) ;
659
+ if ( targetUri ) {
660
+ // Uri passed as command argument might be for a server we haven't yet resolve connection details such as password,
661
+ // so make sure that happens now if needed
662
+ const { configName } = connectionTarget ( targetUri ) ;
663
+ const serverName = targetUri . scheme === "file" ? config ( "conn" , configName ) . server : configName ;
664
+ await resolveConnectionSpec ( serverName ) ;
665
+ } else {
666
+ targetUri = currentFile ( ) ?. uri ;
667
+ if ( ! targetUri ) {
668
+ targetUri = await workspaceUriForTerminal ( ) ;
669
+ }
670
+ }
671
+ const api = new AtelierAPI ( targetUri ) ;
672
+
673
+ // Guarantee we know the apiVersion of the server
674
+ await api . serverInfo ( ) ;
632
675
633
676
// Get the terminal configuration
634
- const terminalOpts = terminalConfigForUri ( api , extensionUri ) ;
677
+ const terminalOpts = terminalConfigForUri ( api , extensionUri , targetUri ) ;
635
678
if ( terminalOpts ) {
636
679
// Launch the terminal
637
680
const terminal = vscode . window . createTerminal ( terminalOpts ) ;
@@ -642,28 +685,13 @@ export async function launchWebSocketTerminal(extensionUri: vscode.Uri): Promise
642
685
export class WebSocketTerminalProfileProvider implements vscode . TerminalProfileProvider {
643
686
constructor ( private readonly _extensionUri : vscode . Uri ) { }
644
687
645
- async provideTerminalProfile ( token : vscode . CancellationToken ) : Promise < vscode . TerminalProfile > {
688
+ async provideTerminalProfile ( _token : vscode . CancellationToken ) : Promise < vscode . TerminalProfile > {
646
689
// Determine the server connection to use
647
- let uri : vscode . Uri ;
648
- const workspaceFolders = vscode . workspace . workspaceFolders || [ ] ;
649
- if ( workspaceFolders . length == 0 ) {
650
- throw new Error ( "WebSocket Terminal requires an open workspace." ) ;
651
- } else if ( workspaceFolders . length == 1 ) {
652
- // Use the current connection
653
- uri = workspaceFolders [ 0 ] . uri ;
654
- } else {
655
- // Pick from the workspace folders
656
- uri = (
657
- await vscode . window . showWorkspaceFolderPick ( {
658
- ignoreFocusOut : true ,
659
- placeHolder : "Pick the workspace folder to get server connection information from" ,
660
- } )
661
- ) ?. uri ;
662
- }
690
+ const uri : vscode . Uri = await workspaceUriForTerminal ( ) ;
663
691
664
692
if ( uri ) {
665
693
// Get the terminal configuration. Will throw if there's an error.
666
- const terminalOpts = terminalConfigForUri ( new AtelierAPI ( uri ) , this . _extensionUri , true ) ;
694
+ const terminalOpts = terminalConfigForUri ( new AtelierAPI ( uri ) , this . _extensionUri , uri , true ) ;
667
695
return new vscode . TerminalProfile ( terminalOpts ) ;
668
696
} else {
669
697
throw new Error ( "WebSocket Terminal requires a selected workspace folder." ) ;
0 commit comments