Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
fdncred committed Sep 19, 2023
2 parents 6383b50 + 7d91ec9 commit 8e2680d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![vsm-downloads](https://img.shields.io/visual-studio-marketplace/d/TheNuProjectContributors.vscode-nushell-lang?style=flat-square&label=downloads&logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=TheNuProjectContributors.vscode-nushell-lang)
[![vsm-installs](https://img.shields.io/visual-studio-marketplace/i/TheNuProjectContributors.vscode-nushell-lang?style=flat-square&label=installs&logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=TheNuProjectContributors.vscode-nushell-lang)

This [extension for VSCode](https://code.visualstudio.com/docs/introvideos/extend) provides editing, syntax highlighting, and IDE support for [Nushell](http://nushell.sh), a data-driven document language.
This [extension for VSCode](https://marketplace.visualstudio.com/items?itemName=TheNuProjectContributors.vscode-nushell-lang) provides editing, syntax highlighting, and IDE support for [Nushell](http://nushell.sh), a data-driven document language.

## Features

Expand Down
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"vscode": "^1.75.0"
},
"dependencies": {
"vscode-languageclient": "^8.1.0"
"vscode-languageclient": "^8.1.0",
"which": "^4.0.0"
},
"devDependencies": {
"@types/vscode": "^1.75.1",
Expand Down
110 changes: 54 additions & 56 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ export function activate(context: vscode.ExtensionContext) {
provideTerminalProfile(
token: vscode.CancellationToken
): vscode.ProviderResult<vscode.TerminalProfile> {
const which = require("which");
const path = require("path");
const fs = require("fs");
const glob = require("glob");
const os = require("os");

const PATH_FROM_ENV = process.env["PATH"];
const pathsToCheck = [
PATH_FROM_ENV,
// cargo install location
"~/.cargo/bin/nu",
"~/.cargo/bin/nu.exe",
(process.env["CARGO_HOME"] || "~/.cargo") + "/bin",

// winget on Windows install location
"c:\\program files\\nu\\bin\\nu.exe",
"c:\\program files\\nu\\bin",
// just add a few other drives for fun
"d:\\program files\\nu\\bin\\nu.exe",
"e:\\program files\\nu\\bin\\nu.exe",
"f:\\program files\\nu\\bin\\nu.exe",
"d:\\program files\\nu\\bin",
"e:\\program files\\nu\\bin",
"f:\\program files\\nu\\bin",

// SCOOP:TODO
// all user installed programs and scoop itself install to
// c:\users\<user>\scoop\ unless SCOOP env var is set
// globally installed programs go in
// c:\programdata\scoop unless SCOOP_GLOBAL env var is set
// scoop install location
"~/scoop/apps/nu/*/nu.exe",
"~/scoop/shims/nu.exe",
// SCOOP should already set up the correct `PATH` env var
//"~/scoop/apps/nu/*/nu.exe",
//"~/scoop/shims/nu.exe",

// chocolatey install location - same as winget
// 'c:\\program files\\nu\\bin\\nu.exe',
Expand All @@ -60,59 +60,57 @@ export function activate(context: vscode.ExtensionContext) {

// brew install location mac
// intel
"/usr/local/bin/nu",
"/usr/local/bin",
// arm
"/opt/homebrew/bin/nu",
"/opt/homebrew/bin",

// native package manager install location
"/usr/bin/nu",
// standard location should be in `PATH` env var
//"/usr/bin/nu",
];

let found_nushell_path = "";
const home = os.homedir();

for (const cur_val of pathsToCheck) {
// console.log("Inspecting location: " + cur_val);
let constructed_file = "";
if (cur_val.startsWith("~/scoop")) {
// console.log("Found scoop: " + cur_val);
const p = path.join(home, cur_val.slice(1));
// console.log("Expanded ~: " + p);
const file = glob.sync(p, "debug").toString();
// console.log("Glob for files: " + file);

if (file) {
// console.log("Found some file: " + file);
// if there are slashes, reverse them to back slashes
constructed_file = file.replace(/\//g, "\\");
const found_nushell_path = which.sync("nu", {
nothrow: true,
path: pathsToCheck.join(path.delimiter),
});

if (found_nushell_path == null) {
console.log(
"Nushell not found in env:PATH or any of the heuristic locations."
);
// use an async arrow funciton to use `await` inside
return (async () => {
if (
(await vscode.window.showErrorMessage(
"We cannot find a nushell executable in your path or pre-defined locations",
"install from website"
)) &&
(await vscode.env.openExternal(
vscode.Uri.parse("https://www.nushell.sh/")
)) &&
(await vscode.window.showInformationMessage(
"after you install nushell, you might need to reload vscode",
"reload now"
))
) {
vscode.commands.executeCommand("workbench.action.reloadWindow");
}
} else if (cur_val.startsWith("~")) {
constructed_file = path.join(home, cur_val.slice(1));
// console.log("Found ~, constructing path: " + constructed_file);
} else {
constructed_file = cur_val;
}

if (fs.existsSync(constructed_file)) {
// console.log("File exists, returning: " + constructed_file);
found_nushell_path = constructed_file;
break;
} else {
// console.log("File not found: " + constructed_file);
}
// user has already seen error messages, but they didn't click through
// return a promise that never resolve to supress the confusing error
return await new Promise(() => undefined);
})();
}

if (found_nushell_path.length > 0) {
return {
options: {
name: "Nushell",
shellPath: found_nushell_path,
},
};
} else {
console.log("Nushell not found, returning undefined");
return undefined;
}
return {
options: {
name: "Nushell",
shellPath: found_nushell_path,
iconPath: vscode.Uri.joinPath(
context.extensionUri,
"assets/nu.svg"
),
},
};
},
})
);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"light": "assets/nu.svg",
"dark": "assets/nu.svg"
},
"firstLine": "^#!\\s*/?.*\\bnu\\b",
"configuration": "./language-configuration.json"
}
],
Expand Down

0 comments on commit 8e2680d

Please sign in to comment.