forked from microsoft/vscode-azurecli
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc8e37c
commit 62f8691
Showing
10 changed files
with
1,065 additions
and
787 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,81 +1,93 @@ | ||
import { never } from './utils'; | ||
import { never } from "./utils"; | ||
|
||
export type TokenKind = 'subcommand' | 'argument_name' | 'argument_value' | 'comment'; | ||
export type TokenKind = | ||
| "subcommand" | ||
| "argument_name" | ||
| "argument_value" | ||
| "comment"; | ||
|
||
export interface Token { | ||
kind: TokenKind; | ||
offset: number; | ||
length: number; | ||
text: string; | ||
kind: TokenKind; | ||
offset: number; | ||
length: number; | ||
text: string; | ||
} | ||
|
||
export interface Argument { | ||
name?: Token; | ||
value?: Token; | ||
name?: Token; | ||
value?: Token; | ||
} | ||
|
||
export interface Command { | ||
tokens: Token[]; | ||
subcommand: Token[]; | ||
arguments: Argument[]; | ||
comment?: Token; | ||
tokens: Token[]; | ||
subcommand: Token[]; | ||
arguments: Argument[]; | ||
comment?: Token; | ||
} | ||
|
||
export function parse(line: string) { | ||
const regex = /"[^"]*"|'[^']*'|\#.*|[^\s"'#]+/g; | ||
const tokens: Token[] = []; | ||
let subcommand = true; | ||
let m; | ||
while (m = regex.exec(line)) { | ||
const text = m[0]; | ||
const length = text.length; | ||
const isArgument = text.startsWith('-'); | ||
const isComment = text.startsWith('#'); | ||
if (isArgument || isComment) { | ||
subcommand = false; | ||
} | ||
tokens.push({ | ||
kind: subcommand ? 'subcommand' : isArgument ? 'argument_name' : | ||
isComment ? 'comment' : 'argument_value', | ||
offset: regex.lastIndex - length, | ||
length, | ||
text | ||
}); | ||
} | ||
|
||
const command: Command = { | ||
tokens, | ||
subcommand: [], | ||
arguments: [] | ||
}; | ||
const args = command.arguments; | ||
const regex = /"[^"]*"|'[^']*'|\#.*|[^\s"'#]+/g; | ||
const tokens: Token[] = []; | ||
let subcommand = true; | ||
let m; | ||
while ((m = regex.exec(line))) { | ||
const text = m[0]; | ||
const length = text.length; | ||
const isArgument = text.startsWith("-"); | ||
const isComment = text.startsWith("#"); | ||
if (isArgument || isComment) { | ||
subcommand = false; | ||
} | ||
tokens.push({ | ||
kind: subcommand | ||
? "subcommand" | ||
: isArgument | ||
? "argument_name" | ||
: isComment | ||
? "comment" | ||
: "argument_value", | ||
offset: regex.lastIndex - length, | ||
length, | ||
text, | ||
}); | ||
} | ||
|
||
for (const token of tokens) { | ||
switch (token.kind) { | ||
case 'subcommand': | ||
command.subcommand.push(token); | ||
break; | ||
case 'argument_name': | ||
args.push({ name: token }); | ||
break; | ||
case 'argument_value': | ||
if (args.length && !('value' in args[args.length - 1])) { | ||
args[args.length - 1].value = token; | ||
} else { | ||
args.push({ value: token }); | ||
} | ||
break; | ||
case 'comment': | ||
command.comment = token; | ||
break; | ||
default: | ||
never(token.kind); | ||
} | ||
} | ||
const command: Command = { | ||
tokens, | ||
subcommand: [], | ||
arguments: [], | ||
}; | ||
const args = command.arguments; | ||
|
||
return command; | ||
for (const token of tokens) { | ||
switch (token.kind) { | ||
case "subcommand": | ||
command.subcommand.push(token); | ||
break; | ||
case "argument_name": | ||
args.push({ name: token }); | ||
break; | ||
case "argument_value": | ||
if (args.length && !("value" in args[args.length - 1])) { | ||
args[args.length - 1].value = token; | ||
} else { | ||
args.push({ value: token }); | ||
} | ||
break; | ||
case "comment": | ||
command.comment = token; | ||
break; | ||
default: | ||
never(token.kind); | ||
} | ||
} | ||
|
||
return command; | ||
} | ||
|
||
export function findNode(command: Command, offset: number) { | ||
return command.tokens.find(token => token.offset <= offset && token.offset + token.length > offset); | ||
return command.tokens.find( | ||
(token) => | ||
token.offset <= offset && token.offset + token.length > offset, | ||
); | ||
} |
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 |
---|---|---|
@@ -1,50 +1,50 @@ | ||
import * as cp from 'child_process'; | ||
import * as fs from 'fs'; | ||
import * as cp from "child_process"; | ||
import * as fs from "fs"; | ||
|
||
export interface ExecResult { | ||
error: Error | null; | ||
stdout: string; | ||
stderr: string; | ||
error: Error | null; | ||
stdout: string; | ||
stderr: string; | ||
} | ||
|
||
export function exec(command: string) { | ||
return new Promise<ExecResult>((resolve, reject) => { | ||
cp.exec(command, (error, stdout, stderr) => { | ||
(error ? reject : resolve)({ error, stdout, stderr }); | ||
}); | ||
}); | ||
return new Promise<ExecResult>((resolve, reject) => { | ||
cp.exec(command, (error, stdout, stderr) => { | ||
(error ? reject : resolve)({ error, stdout, stderr }); | ||
}); | ||
}); | ||
} | ||
|
||
export function realpath(path: string) { | ||
return new Promise<string>((resolve, reject) => { | ||
fs.realpath(path, (error, resolvedPath) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(resolvedPath); | ||
} | ||
}); | ||
}); | ||
return new Promise<string>((resolve, reject) => { | ||
fs.realpath(path, (error, resolvedPath) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(resolvedPath); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export function exists(path: string) { | ||
return new Promise<boolean>(resolve => { | ||
fs.exists(path, resolve); | ||
}); | ||
return new Promise<boolean>((resolve) => { | ||
fs.exists(path, resolve); | ||
}); | ||
} | ||
|
||
export function readdir(path: string) { | ||
return new Promise<string[]>((resolve, reject) => { | ||
fs.readdir(path, (error, files) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(files); | ||
} | ||
}); | ||
}); | ||
return new Promise<string[]>((resolve, reject) => { | ||
fs.readdir(path, (error, files) => { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(files); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export function never(n: never) { | ||
throw new Error(`Should not happen: ${n}`); | ||
throw new Error(`Should not happen: ${n}`); | ||
} |
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 |
---|---|---|
@@ -1,24 +1,20 @@ | ||
{ | ||
"comments": { | ||
"lineComment": "#" | ||
}, | ||
"brackets": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"] | ||
], | ||
"autoClosingPairs": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"], | ||
["\"", "\""], | ||
["'", "'"] | ||
], | ||
"surroundingPairs": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"], | ||
["\"", "\""], | ||
["'", "'"] | ||
] | ||
} | ||
"comments": { | ||
"lineComment": "#" | ||
}, | ||
"brackets": [["{", "}"], ["[", "]"], ["(", ")"]], | ||
"autoClosingPairs": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"], | ||
["\"", "\""], | ||
["'", "'"] | ||
], | ||
"surroundingPairs": [ | ||
["{", "}"], | ||
["[", "]"], | ||
["(", ")"], | ||
["\"", "\""], | ||
["'", "'"] | ||
] | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"runLineInTerminal.title": "Run Line in Terminal", | ||
"runLineInEditor.title": "Run Line in Editor", | ||
"toggleLiveQuery.title": "Toggle Live Query", | ||
"installAzureCLI.title": "Install the Azure CLI", | ||
"configuration.title": "Azure CLI Tools Configuration", | ||
"azureCLI.showResultInNewEditor.description": "Controls whether showing the result from running an Azure CLI command in an editor should always create a new editor.", | ||
"azureCLI.lineContinuationCharacter.description": "Override the default continuation character (backtick [`] on Windows otherwise backslash [\\]) used for multiline commands" | ||
"runLineInTerminal.title": "Run Line in Terminal", | ||
"runLineInEditor.title": "Run Line in Editor", | ||
"toggleLiveQuery.title": "Toggle Live Query", | ||
"installAzureCLI.title": "Install the Azure CLI", | ||
"configuration.title": "Azure CLI Tools Configuration", | ||
"azureCLI.showResultInNewEditor.description": "Controls whether showing the result from running an Azure CLI command in an editor should always create a new editor.", | ||
"azureCLI.lineContinuationCharacter.description": "Override the default continuation character (backtick [`] on Windows otherwise backslash [\\]) used for multiline commands" | ||
} |
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
Oops, something went wrong.