Skip to content

Commit

Permalink
add install.ps1 to the package; add notification for auto installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Jun 26, 2019
1 parent c84a91e commit ce33135
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
26 changes: 22 additions & 4 deletions client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,36 @@ import Shell from "node-powershell";

const cocPowerShellRoot = path.join(__dirname, "..", "..");
const bundledModulesPath = path.join(cocPowerShellRoot, "PowerShellEditorServices");
// TODO configuration for log path?

This comment has been minimized.

Copy link
@TylerLeonhardt

TylerLeonhardt Jun 26, 2019

Collaborator

Yeah I was just lazy, this should be a "guid-pid".

const logPath = path.join(cocPowerShellRoot, "/.pses/logs/1234");
// TODO log redirection?
const logger = workspace.createOutputChannel("coc-powershell");

export async function activate(context: ExtensionContext) {
const pwshPath = getDefaultPowerShellPath(getPlatformDetails())

logger.appendLine("starting.")
logger.appendLine(`pwshPath = ${pwshPath}`)
logger.appendLine(`bundledModulesPath = ${bundledModulesPath}`)

// If PowerShellEditorServices is not downloaded yet, run the install script to do so.
if (!fs.existsSync(bundledModulesPath)) {
let notification = workspace.createStatusBarItem(0, { progress: true})
notification.text = "Downloading PowerShellEditorServices..."
notification.show()

const ps = new Shell({
executionPolicy: 'Bypass',
noProfile: true
});

ps.addCommand(path.join(cocPowerShellRoot, "install.ps1"));
await ps.invoke();
await ps.invoke()
.catch(e => logger.appendLine("error downloading PSES: " + e))
.finally(() => {
notification.hide()
notification.dispose()
});

}

let serverOptions: ServerOptions = {
Expand All @@ -51,13 +67,12 @@ export async function activate(context: ExtensionContext) {

// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for F# documents
// Register the server for powershell documents
documentSelector: [{ scheme: 'file', language: 'ps1' }],
synchronize: {
// Synchronize the setting section 'powershell' to the server
configurationSection: 'ps1',
// Notify the server about file changes to PowerShell files contain in the workspace
// TODO: is there a way to configure this via the language server protocol?
fileEvents: [
workspace.createFileSystemWatcher('**/*.ps1'),
workspace.createFileSystemWatcher('**/*.psd1'),
Expand All @@ -76,6 +91,9 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand('powershell.command.goto', goto);
}

// NOTE (yatli): this is in fact due to coc-fsharp CodeLens using a custom command
// if PSES is not using a 'goto' codelens command we can discard this one.
// Also, any other pwsh codelens/general commands, like "test this", "evaluate"? they could be implemented like this one

This comment has been minimized.

Copy link
@TylerLeonhardt

TylerLeonhardt Jun 26, 2019

Collaborator

Ah we don't have this 'goto' codelens.

The only codelens's we have are 'references' and 'Pester tests'

function goto(file: string, startLine: number, startColumn: number, _endLine: number, _endColumn: number) {
let selection = Range.create(startLine, startColumn, startLine, startColumn);
workspace.jumpTo(file, selection.start);
Expand Down
18 changes: 3 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"main": "out/client/extension.js",
"files": [
"out",
"syntaxes"
"syntaxes",
"install.ps1"
],
"contributes": {
"languages": [
Expand Down

0 comments on commit ce33135

Please sign in to comment.