-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open path from URI #2038
Draft
worksofliam
wants to merge
8
commits into
master
Choose a base branch
from
feature/uri_cleanup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Open path from URI #2038
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
06a4004
Seperate URI handler and sandbox
worksofliam 6ba2544
Add new URI handler to open a file
worksofliam 42bc8e3
Merge branch 'master' into feature/uri_cleanup
worksofliam b7652bd
Merge branch 'master' into feature/uri_cleanup
worksofliam 9c266cd
Add warning messages
worksofliam 7a6a00b
Build commit
worksofliam aef0402
Merge branch 'master' into feature/uri_cleanup
worksofliam 61b209e
Ability to connect to system from open
worksofliam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,153 @@ | ||||||
import querystring from "querystring"; | ||||||
import { commands, ExtensionContext, Uri, window } from "vscode"; | ||||||
import { ConnectionManager, GlobalConfiguration } from "../api/Configuration"; | ||||||
import { instance } from "../instantiate"; | ||||||
import { t } from "../locale"; | ||||||
import { ConnectionData } from "../typings"; | ||||||
import { initialSandboxSetup } from "../sandbox"; | ||||||
|
||||||
export async function registerUriHandler(context: ExtensionContext) { | ||||||
context.subscriptions.push( | ||||||
window.registerUriHandler({ | ||||||
async handleUri(uri: Uri) { | ||||||
const queryData = querystring.parse(uri.query); | ||||||
|
||||||
const connection = instance.getConnection(); | ||||||
|
||||||
switch (uri.path) { | ||||||
case '/open': | ||||||
if (queryData.path) { | ||||||
if (queryData.host) { | ||||||
const host = Array.isArray(queryData.host) ? queryData.host[0] : queryData.host; | ||||||
if (connection) { | ||||||
if (host !== connection.currentHost) { | ||||||
const chosen = await window.showInformationMessage(t(`uriOpen.openError`), { | ||||||
detail: t(`uriOpen.hostMismatch`), | ||||||
modal: true | ||||||
}, `Open`); | ||||||
|
||||||
if (chosen !== `Open`) { | ||||||
return; | ||||||
} | ||||||
} | ||||||
} else { | ||||||
const connection = ConnectionManager.getByHost(host, true) || ConnectionManager.getByName(host, true); | ||||||
if (connection) { | ||||||
let password = await ConnectionManager.getStoredPassword(context, connection.data.name); | ||||||
|
||||||
if (!password) { | ||||||
password = await window.showInputBox({ | ||||||
password: true, | ||||||
title: t(`sandbox.input.password.title`), | ||||||
prompt: t(`sandbox.input.password.prompt`, connection.data.username, connection.data.host) | ||||||
}); | ||||||
} | ||||||
|
||||||
const connected = await commands.executeCommand(`code-for-ibmi.connectDirect`, { | ||||||
...connection.data, | ||||||
password | ||||||
}); | ||||||
|
||||||
if (!connected) { | ||||||
window.showWarningMessage(t(`uriOpen.noConnection`)); | ||||||
return; | ||||||
}; | ||||||
} else { | ||||||
window.showWarningMessage(t(`uriOpen.noConnection`)); | ||||||
return; | ||||||
} | ||||||
} | ||||||
|
||||||
const paths = Array.isArray(queryData.path) ? queryData.path : [queryData.path]; | ||||||
for (const path of paths) { | ||||||
commands.executeCommand(`code-for-ibmi.openEditable`, path); | ||||||
} | ||||||
} else { | ||||||
window.showWarningMessage(t(`uriOpen.missingPath`)); | ||||||
} | ||||||
} else { | ||||||
window.showWarningMessage(t(`uriOpen.noConnection`)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
break; | ||||||
|
||||||
case `/connect`: | ||||||
if (connection === undefined) { | ||||||
const save = queryData.save === `true`; | ||||||
const server = String(queryData.server); | ||||||
let user: string | string[] | undefined = queryData.user; | ||||||
let pass: string | string[] | undefined = queryData.pass; | ||||||
|
||||||
if (server) { | ||||||
if (!user) { | ||||||
user = await window.showInputBox({ | ||||||
title: t(`sandbox.input.user.title`), | ||||||
prompt: t(`sandbox.input.user.prompt`, server) | ||||||
}); | ||||||
} | ||||||
|
||||||
if (pass) { | ||||||
pass = Buffer.from(String(pass), `base64`).toString(); | ||||||
} else { | ||||||
pass = await window.showInputBox({ | ||||||
password: true, | ||||||
title: t(`sandbox.input.password.title`), | ||||||
prompt: t(`sandbox.input.password.prompt`, String(user), server) | ||||||
}); | ||||||
} | ||||||
|
||||||
if (user && pass) { | ||||||
const serverParts = String(server).split(`:`); | ||||||
const host = serverParts[0]; | ||||||
const port = serverParts.length === 2 ? Number(serverParts[1]) : 22; | ||||||
|
||||||
const connectionData: ConnectionData = { | ||||||
host, | ||||||
name: `${user}-${host}`, | ||||||
username: String(user), | ||||||
password: String(pass), | ||||||
port | ||||||
}; | ||||||
|
||||||
const connectionResult = await commands.executeCommand(`code-for-ibmi.connectDirect`, connectionData); | ||||||
|
||||||
if (connectionResult) { | ||||||
await initialSandboxSetup(connectionData.username); | ||||||
|
||||||
if (save) { | ||||||
const existingConnection = ConnectionManager.getByHost(host); | ||||||
|
||||||
if (!existingConnection) { | ||||||
await ConnectionManager.storeNew({ | ||||||
...connectionData, | ||||||
password: undefined, // Removes the password from the object | ||||||
}); | ||||||
|
||||||
await ConnectionManager.setStoredPassword(context, host, pass); | ||||||
} | ||||||
} | ||||||
|
||||||
} else { | ||||||
window.showInformationMessage(t(`sandbox.failedToConnect.title`), { | ||||||
modal: true, | ||||||
detail: t(`sandbox.failedToConnect`, server, user) | ||||||
}); | ||||||
} | ||||||
|
||||||
} else { | ||||||
window.showErrorMessage(t(`sandbox.noPassword`, server)); | ||||||
} | ||||||
} | ||||||
} else { | ||||||
window.showInformationMessage(t(`sandbox.failedToConnect.title`), { | ||||||
modal: true, | ||||||
detail: t(`sandbox.alreadyConnected`) | ||||||
}); | ||||||
} | ||||||
|
||||||
break; | ||||||
} | ||||||
|
||||||
} | ||||||
}) | ||||||
); | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the example you gave in this PR:
I assume this means that the file will be opened based on the active connection. If so, is this else block a mistake because this will not open any file and just give this warning even though I am connected. In the case there is no connection, shouldn't the message be: