Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0013ead

Browse files
authored
Automatically start workspace when explicitly opening (#587)
Closes#582
1 parent9ff3cb6 commit0013ead

File tree

5 files changed

+182
-140
lines changed

5 files changed

+182
-140
lines changed

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
###Changed
66

77
- Always enable verbose (`-v`) flag when a log directory is configured (`coder.proxyLogDir`).
8-
- Automatically start a workspace if it is opened but not running.
8+
- Automatically start a workspacewithout promptingif it is explicitly opened but not running.
99

1010
###Added
1111

‎src/commands.ts‎

Lines changed: 124 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ export class Commands {
451451
thrownewError("You are not logged in");
452452
}
453453
if(iteminstanceofAgentTreeItem){
454-
awaitopenWorkspace(
454+
awaitthis.openWorkspace(
455455
baseUrl,
456456
item.workspace,
457457
item.agent,
@@ -465,7 +465,13 @@ export class Commands {
465465
// User declined to pick an agent.
466466
return;
467467
}
468-
awaitopenWorkspace(baseUrl,item.workspace,agent,undefined,true);
468+
awaitthis.openWorkspace(
469+
baseUrl,
470+
item.workspace,
471+
agent,
472+
undefined,
473+
true,
474+
);
469475
}else{
470476
thrownewError("Unable to open unknown sidebar item");
471477
}
@@ -583,7 +589,7 @@ export class Commands {
583589
return;
584590
}
585591

586-
awaitopenWorkspace(baseUrl,workspace,agent,folderPath,openRecent);
592+
awaitthis.openWorkspace(baseUrl,workspace,agent,folderPath,openRecent);
587593
}
588594

589595
/**
@@ -605,15 +611,49 @@ export class Commands {
605611
thrownewError("You are not logged in");
606612
}
607613

608-
awaitopenDevContainer(
614+
constremoteAuthority=toRemoteAuthority(
609615
baseUrl,
610616
workspaceOwner,
611617
workspaceName,
612618
workspaceAgent,
613-
devContainerName,
614-
devContainerFolder,
615-
localWorkspaceFolder,
616-
localConfigFile,
619+
);
620+
621+
consthostPath=localWorkspaceFolder ?localWorkspaceFolder :undefined;
622+
constconfigFile=
623+
hostPath&&localConfigFile
624+
?{
625+
path:localConfigFile,
626+
scheme:"vscode-fileHost",
627+
}
628+
:undefined;
629+
constdevContainer=Buffer.from(
630+
JSON.stringify({
631+
containerName:devContainerName,
632+
hostPath,
633+
configFile,
634+
localDocker:false,
635+
}),
636+
"utf-8",
637+
).toString("hex");
638+
639+
consttype=localWorkspaceFolder ?"dev-container" :"attached-container";
640+
constdevContainerAuthority=`${type}+${devContainer}@${remoteAuthority}`;
641+
642+
letnewWindow=true;
643+
if(!vscode.workspace.workspaceFolders?.length){
644+
newWindow=false;
645+
}
646+
647+
// Only set the memento if when opening a new folder
648+
awaitthis.storage.setFirstConnect();
649+
awaitvscode.commands.executeCommand(
650+
"vscode.openFolder",
651+
vscode.Uri.from({
652+
scheme:"vscode-remote",
653+
authority:devContainerAuthority,
654+
path:devContainerFolder,
655+
}),
656+
newWindow,
617657
);
618658
}
619659

@@ -722,141 +762,89 @@ export class Commands {
722762
}
723763
returnagents;
724764
}
725-
}
726-
727-
/**
728-
* Given a workspace and agent, build the host name, find a directory to open,
729-
* and pass both to the Remote SSH plugin in the form of a remote authority
730-
* URI.
731-
*
732-
* If provided, folderPath is always used, otherwise expanded_directory from
733-
* the agent is used.
734-
*/
735-
asyncfunctionopenWorkspace(
736-
baseUrl:string,
737-
workspace:Workspace,
738-
agent:WorkspaceAgent,
739-
folderPath:string|undefined,
740-
openRecent:boolean=false,
741-
){
742-
constremoteAuthority=toRemoteAuthority(
743-
baseUrl,
744-
workspace.owner_name,
745-
workspace.name,
746-
agent.name,
747-
);
748-
749-
letnewWindow=true;
750-
// Open in the existing window if no workspaces are open.
751-
if(!vscode.workspace.workspaceFolders?.length){
752-
newWindow=false;
753-
}
754-
755-
if(!folderPath){
756-
folderPath=agent.expanded_directory;
757-
}
758765

759-
// If the agent had no folder or we have been asked to open the most recent,
760-
// we can try to open a recently opened folder/workspace.
761-
if(!folderPath||openRecent){
762-
constoutput:{
763-
workspaces:{folderUri:vscode.Uri;remoteAuthority:string}[];
764-
}=awaitvscode.commands.executeCommand("_workbench.getRecentlyOpened");
765-
constopened=output.workspaces.filter(
766-
// Remove recents that do not belong to this connection. The remote
767-
// authority maps to a workspace/agent combination (using the SSH host
768-
// name). There may also be some legacy connections that still may
769-
// reference a workspace without an agent name, which will be missed.
770-
(opened)=>opened.folderUri?.authority===remoteAuthority,
766+
/**
767+
* Given a workspace and agent, build the host name, find a directory to open,
768+
* and pass both to the Remote SSH plugin in the form of a remote authority
769+
* URI.
770+
*
771+
* If provided, folderPath is always used, otherwise expanded_directory from
772+
* the agent is used.
773+
*/
774+
asyncopenWorkspace(
775+
baseUrl:string,
776+
workspace:Workspace,
777+
agent:WorkspaceAgent,
778+
folderPath:string|undefined,
779+
openRecent:boolean=false,
780+
){
781+
constremoteAuthority=toRemoteAuthority(
782+
baseUrl,
783+
workspace.owner_name,
784+
workspace.name,
785+
agent.name,
771786
);
772787

773-
// openRecent will always use the most recent. Otherwise, if there are
774-
// multiple we ask the user which to use.
775-
if(opened.length===1||(opened.length>1&&openRecent)){
776-
folderPath=opened[0].folderUri.path;
777-
}elseif(opened.length>1){
778-
constitems=opened.map((f)=>f.folderUri.path);
779-
folderPath=awaitvscode.window.showQuickPick(items,{
780-
title:"Select a recently opened folder",
781-
});
782-
if(!folderPath){
783-
// User aborted.
784-
return;
785-
}
788+
letnewWindow=true;
789+
// Open in the existing window if no workspaces are open.
790+
if(!vscode.workspace.workspaceFolders?.length){
791+
newWindow=false;
786792
}
787-
}
788793

789-
if(folderPath){
790-
awaitvscode.commands.executeCommand(
791-
"vscode.openFolder",
792-
vscode.Uri.from({
793-
scheme:"vscode-remote",
794-
authority:remoteAuthority,
795-
path:folderPath,
796-
}),
797-
// Open this in a new window!
798-
newWindow,
799-
);
800-
return;
801-
}
794+
if(!folderPath){
795+
folderPath=agent.expanded_directory;
796+
}
802797

803-
// This opens the workspace without an active folder opened.
804-
awaitvscode.commands.executeCommand("vscode.newWindow",{
805-
remoteAuthority:remoteAuthority,
806-
reuseWindow:!newWindow,
807-
});
808-
}
798+
// If the agent had no folder or we have been asked to open the most recent,
799+
// we can try to open a recently opened folder/workspace.
800+
if(!folderPath||openRecent){
801+
constoutput:{
802+
workspaces:{folderUri:vscode.Uri;remoteAuthority:string}[];
803+
}=awaitvscode.commands.executeCommand("_workbench.getRecentlyOpened");
804+
constopened=output.workspaces.filter(
805+
// Remove recents that do not belong to this connection. The remote
806+
// authority maps to a workspace/agent combination (using the SSH host
807+
// name). There may also be some legacy connections that still may
808+
// reference a workspace without an agent name, which will be missed.
809+
(opened)=>opened.folderUri?.authority===remoteAuthority,
810+
);
809811

810-
asyncfunctionopenDevContainer(
811-
baseUrl:string,
812-
workspaceOwner:string,
813-
workspaceName:string,
814-
workspaceAgent:string,
815-
devContainerName:string,
816-
devContainerFolder:string,
817-
localWorkspaceFolder:string="",
818-
localConfigFile:string="",
819-
){
820-
constremoteAuthority=toRemoteAuthority(
821-
baseUrl,
822-
workspaceOwner,
823-
workspaceName,
824-
workspaceAgent,
825-
);
826-
827-
consthostPath=localWorkspaceFolder ?localWorkspaceFolder :undefined;
828-
constconfigFile=
829-
hostPath&&localConfigFile
830-
?{
831-
path:localConfigFile,
832-
scheme:"vscode-fileHost",
812+
// openRecent will always use the most recent. Otherwise, if there are
813+
// multiple we ask the user which to use.
814+
if(opened.length===1||(opened.length>1&&openRecent)){
815+
folderPath=opened[0].folderUri.path;
816+
}elseif(opened.length>1){
817+
constitems=opened.map((f)=>f.folderUri.path);
818+
folderPath=awaitvscode.window.showQuickPick(items,{
819+
title:"Select a recently opened folder",
820+
});
821+
if(!folderPath){
822+
// User aborted.
823+
return;
833824
}
834-
:undefined;
835-
constdevContainer=Buffer.from(
836-
JSON.stringify({
837-
containerName:devContainerName,
838-
hostPath,
839-
configFile,
840-
localDocker:false,
841-
}),
842-
"utf-8",
843-
).toString("hex");
844-
845-
consttype=localWorkspaceFolder ?"dev-container" :"attached-container";
846-
constdevContainerAuthority=`${type}+${devContainer}@${remoteAuthority}`;
847-
848-
letnewWindow=true;
849-
if(!vscode.workspace.workspaceFolders?.length){
850-
newWindow=false;
851-
}
825+
}
826+
}
852827

853-
awaitvscode.commands.executeCommand(
854-
"vscode.openFolder",
855-
vscode.Uri.from({
856-
scheme:"vscode-remote",
857-
authority:devContainerAuthority,
858-
path:devContainerFolder,
859-
}),
860-
newWindow,
861-
);
828+
// Only set the memento if when opening a new folder/window
829+
awaitthis.storage.setFirstConnect();
830+
if(folderPath){
831+
awaitvscode.commands.executeCommand(
832+
"vscode.openFolder",
833+
vscode.Uri.from({
834+
scheme:"vscode-remote",
835+
authority:remoteAuthority,
836+
path:folderPath,
837+
}),
838+
// Open this in a new window!
839+
newWindow,
840+
);
841+
return;
842+
}
843+
844+
// This opens the workspace without an active folder opened.
845+
awaitvscode.commands.executeCommand("vscode.newWindow",{
846+
remoteAuthority:remoteAuthority,
847+
reuseWindow:!newWindow,
848+
});
849+
}
862850
}

‎src/extension.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
5757
ctx.logUri,
5858
);
5959

60+
// Try to clear this flag ASAP then pass it around if needed
61+
constisFirstConnect=awaitstorage.getAndClearFirstConnect();
62+
6063
// This client tracks the current login and will be used through the life of
6164
// the plugin to poll workspaces for the current login, as well as being used
6265
// in commands that operate on the current login.
@@ -309,7 +312,10 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
309312
ctx.extensionMode,
310313
);
311314
try{
312-
constdetails=awaitremote.setup(vscodeProposed.env.remoteAuthority);
315+
constdetails=awaitremote.setup(
316+
vscodeProposed.env.remoteAuthority,
317+
isFirstConnect,
318+
);
313319
if(details){
314320
// Authenticate the plugin client which is used in the sidebar to display
315321
// workspaces belonging to this deployment.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp