Skip to content

Commit 2e76f4c

Browse files
committed
open terminal with docker-compose
1 parent ac00254 commit 2e76f4c

File tree

6 files changed

+89
-62
lines changed

6 files changed

+89
-62
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ To be able to use many plugin features, you need to configure the connection to
5050
Or you can edit it through settings editor. Which you can open from menu *Code* > *Preferences* > *Settings* for macOS or *File* > *Preferences* > *Settings* for Windows, search for "workspace settings" through Command Palette [⌘⇧P/Ctrl+Shift+P] or by shortcut [⌘,/Ctrl+,].
5151

5252
- Find a 'objectscript', do not forget to set `active` to `true`
53-
`port` should follow to web port of instance (usually by default, 57772 for Caché/Ensemble, 52773 for IRIS) ![Settings UI](https://raw.githubusercontent.com/daimor/vscode-objectscript/master/images/settings.png)
53+
`port` should follow to web port of instance (usually by default, 52773 for Caché/Ensemble, 52773 for IRIS) ![Settings UI](https://raw.githubusercontent.com/daimor/vscode-objectscript/master/images/settings.png)
5454
- Change settings according to your Caché/IRIS instance
5555
- You will see related output in "Output" while switched to "ObjectScript" channel (right drop-down menu on top of the output window)
5656

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@
481481
"description": "Name of service in docker-compose",
482482
"type": "string"
483483
},
484-
"objectscript.conn.docker-compose.port": {
484+
"objectscript.conn.docker-compose.internalPort": {
485485
"description": "Target port inside the service in docker-compose",
486486
"type": "number",
487487
"default": 52773
@@ -720,7 +720,7 @@
720720
"prettier": "^1.18.2",
721721
"tape": "^4.11.0",
722722
"typescript": "^3.6.3",
723-
"vsce": "^1.67.1",
723+
"vsce": "^1.70.0",
724724
"vscode-debugadapter-testsupport": "^1.37.1",
725725
"vscode-test": "^1.2.0"
726726
},

src/commands/serverActions.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode";
2-
import { config, workspaceState } from "../extension";
3-
import { currentWorkspaceFolder } from "../utils";
2+
import { config, workspaceState, checkConnection } from "../extension";
3+
import { currentWorkspaceFolder, terminalWithDocker } from "../utils";
44

55
export async function serverActions(): Promise<void> {
66
const { active, host, ns, https, port: defaultPort, username, password } = config("conn");
@@ -14,9 +14,24 @@ export async function serverActions(): Promise<void> {
1414
const auth = iris
1515
? `&IRISUsername=${username}&IRISPassword=${password}`
1616
: `&CacheUserName=${username}&CachePassword=${password}`;
17+
18+
const terminal = [];
19+
if (workspaceState.get(workspaceFolder + ":docker", true)) {
20+
terminal.push({
21+
id: "openDockerTerminal",
22+
label: "Open terminal in docker",
23+
detail: "Use docker-compose to start session inside configured service",
24+
});
25+
}
1726
return vscode.window
1827
.showQuickPick(
1928
[
29+
{
30+
id: "refreshConnection",
31+
label: "Refresh connection",
32+
detail: "Force attempt to connect to the server",
33+
},
34+
...terminal,
2035
{
2136
detail: "Enable/Disable current connection",
2237
id: "toggleConnection",
@@ -53,6 +68,13 @@ export async function serverActions(): Promise<void> {
5368
vscode.env.openExternal(vscode.Uri.parse(classRef + auth));
5469
break;
5570
}
71+
case "refreshConnection": {
72+
checkConnection();
73+
break;
74+
}
75+
case "openDockerTerminal": {
76+
terminalWithDocker();
77+
}
5678
}
5779
});
5880
}

src/extension.ts

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,55 @@ export function getXmlUri(uri: vscode.Uri): vscode.Uri {
9898
}
9999
let reporter;
100100

101+
export const checkConnection = (clearCookies = false): void => {
102+
const conn = config("conn");
103+
const connInfo = `${conn.host}:${conn.port}[${conn.ns}]`;
104+
panel.text = connInfo;
105+
panel.tooltip = "";
106+
vscode.commands.executeCommand("setContext", "vscode-objectscript.connectActive", conn.active);
107+
if (!conn.active) {
108+
panel.text = `${connInfo} - Disabled`;
109+
return;
110+
}
111+
workspaceState.update(currentWorkspaceFolder() + ":port", undefined);
112+
const { port: dockerPort, docker: withDocker } = portFromDockerCompose(config("conn.docker-compose"), conn.port);
113+
workspaceState.update(currentWorkspaceFolder() + ":docker", withDocker);
114+
if (withDocker) {
115+
terminalWithDocker();
116+
if (dockerPort !== conn.port) {
117+
workspaceState.update(currentWorkspaceFolder() + ":port", dockerPort);
118+
}
119+
}
120+
121+
const api = new AtelierAPI(currentWorkspaceFolder());
122+
if (clearCookies) {
123+
api.clearCookies();
124+
}
125+
api
126+
.serverInfo()
127+
.then(async info => {
128+
// panel.text = `${connInfo} - Connected`;
129+
})
130+
.catch(error => {
131+
let message = error.message;
132+
if (error instanceof StatusCodeError && error.statusCode === 401) {
133+
message = "Not Authorized";
134+
outputChannel.appendLine(
135+
`Authorization error: please check your username/password in the settings,
136+
and if you have sufficient privileges on the server.`
137+
);
138+
} else {
139+
outputChannel.appendLine("Error: " + message);
140+
outputChannel.appendLine("Please check your network settings in the settings.");
141+
}
142+
panel.text = `${connInfo} - ERROR`;
143+
panel.tooltip = message;
144+
})
145+
.finally(() => {
146+
explorerProvider.refresh();
147+
});
148+
};
149+
101150
export async function activate(context: vscode.ExtensionContext): Promise<void> {
102151
reporter = new TelemetryReporter(extensionId, extensionVersion, aiKey);
103152

@@ -120,52 +169,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
120169

121170
panel.command = "vscode-objectscript.serverActions";
122171
panel.show();
123-
const checkConnection = (clearCookies = false) => {
124-
const conn = config("conn");
125-
const connInfo = `${conn.host}:${conn.port}[${conn.ns}]`;
126-
panel.text = connInfo;
127-
panel.tooltip = "";
128-
vscode.commands.executeCommand("setContext", "vscode-objectscript.connectActive", conn.active);
129-
if (!conn.active) {
130-
panel.text = `${connInfo} - Disabled`;
131-
return;
132-
}
133-
const { port: dockerPort, docker: withDocker } = portFromDockerCompose(config("conn.docker-compose"), conn.port);
134-
if (withDocker) {
135-
terminal = terminalWithDocker();
136-
if (dockerPort !== conn.port) {
137-
workspaceState.update(currentWorkspaceFolder() + ":port", dockerPort);
138-
}
139-
}
140172

141-
const api = new AtelierAPI(currentWorkspaceFolder());
142-
if (clearCookies) {
143-
api.clearCookies();
144-
}
145-
api
146-
.serverInfo()
147-
.then(async info => {
148-
// panel.text = `${connInfo} - Connected`;
149-
})
150-
.catch(error => {
151-
let message = error.message;
152-
if (error instanceof StatusCodeError && error.statusCode === 401) {
153-
message = "Not Authorized";
154-
outputChannel.appendLine(
155-
`Authorization error: please check your username/password in the settings,
156-
and if you have sufficient privileges on the server.`
157-
);
158-
} else {
159-
outputChannel.appendLine("Error: " + message);
160-
outputChannel.appendLine("Please check your network settings in the settings.");
161-
}
162-
panel.text = `${connInfo} - ERROR`;
163-
panel.tooltip = message;
164-
})
165-
.finally(() => {
166-
explorerProvider.refresh();
167-
});
168-
};
169173
checkConnection();
170174
vscode.workspace.onDidChangeConfiguration(({ affectsConfiguration }) => {
171175
if (affectsConfiguration("objectscript.conn")) {

src/utils/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ export function portFromDockerCompose(options, defaultPort: number): { port: num
128128
if (!options) {
129129
return result;
130130
}
131-
const { file, service, port } = options;
132-
if (!port || !file || !service || service === "") {
131+
const { file = "docker-compose.yml", service, internalPort = 52773 } = options;
132+
if (!internalPort || !file || !service || service === "") {
133133
return result;
134134
}
135135
const cwd = workspaceFolderUri().fsPath;
136-
const cmd = `docker-compose -f ${file} ps ${service}`;
136+
const cmd = `docker-compose -f ${file} port --protocol=tcp ${service} ${internalPort}`;
137137
try {
138138
const serviceLine = execSync(cmd, {
139139
cwd,
@@ -142,12 +142,13 @@ export function portFromDockerCompose(options, defaultPort: number): { port: num
142142
.replace("/r", "")
143143
.split("/n")
144144
.pop();
145-
const servicePortMatch = serviceLine.match(new RegExp(`:(\\d+)->${port}/`));
145+
const servicePortMatch = serviceLine.match(new RegExp(`:(\\d+)`));
146146
if (servicePortMatch) {
147147
const [, newPort] = servicePortMatch;
148148
return { port: parseInt(newPort, 10), docker: true };
149149
}
150150
} catch (e) {
151+
console.log(e);
151152
// nope
152153
}
153154
return result;
@@ -167,7 +168,7 @@ export function terminalWithDocker() {
167168
"-c",
168169
`command -v ccontrol >/dev/null 2>&1 && ccontrol session $ISC_PACKAGE_INSTANCENAME -U ${ns} || iris session $ISC_PACKAGE_INSTANCENAME -U ${ns}`,
169170
]);
170-
terminal.show();
171171
}
172+
terminal.show();
172173
return terminal;
173174
}

0 commit comments

Comments
 (0)