-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #270 from vim-denops/add-client-info
👍 Add client info on Neovim
- Loading branch information
Showing
5 changed files
with
70 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
dirname, | ||
fromFileUrl, | ||
} from "https://deno.land/std@0.197.0/path/mod.ts"; | ||
import { parse, SemVer } from "https://deno.land/std@0.197.0/semver/mod.ts"; | ||
|
||
const decoder = new TextDecoder(); | ||
|
||
export async function getVersion(): Promise<SemVer> { | ||
const cwd = dirname(fromFileUrl(import.meta.url)); | ||
const command = new Deno.Command("git", { | ||
args: ["describe", "--tags", "--always"], | ||
cwd, | ||
stdin: "null", | ||
stdout: "piped", | ||
stderr: "piped", | ||
}); | ||
const { success, stdout, stderr } = await command.output(); | ||
if (!success) { | ||
throw new Error(`failed to estimate version: ${decoder.decode(stderr)}`); | ||
} | ||
return parse(decoder.decode(stdout).trim()); | ||
} | ||
|
||
export async function getVersionOr<T>(fallback: T): Promise<SemVer | T> { | ||
try { | ||
return await getVersion(); | ||
} catch { | ||
return fallback; | ||
} | ||
} |
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