Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Improve Arguments autocompletion provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-shatskyi committed Nov 27, 2015
1 parent 7d18c5e commit 9d14e2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Autocompletion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Executable from './providers/Executable';
import Command from './providers/Command';
import Arguments from './providers/Arguments';
import File from './providers/File';
import Alias from './providers/Alias';
import History from './providers/History';
Expand All @@ -9,7 +9,7 @@ import * as i from './Interfaces';
import Prompt from "./Prompt";

export default class Autocompletion implements i.AutocompletionProvider {
static providers = [new Command(), new Alias(), new Executable(), new File(), new History(), new HistoryExpansion()];
static providers = [new Arguments(), new Alias(), new Executable(), new File(), new History(), new HistoryExpansion()];
static limit = 9;

getSuggestions(prompt: Prompt) {
Expand Down
8 changes: 7 additions & 1 deletion src/providers/Command.ts → src/providers/Arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ export default class Command implements i.AutocompletionProvider {
suggestions: Suggestion[] = [];

async getSuggestions(prompt: Prompt) {
if (prompt.expanded.length < 2) {
return [];
}

try {
parser.yy.parseError = (err: any, hash: any) => {
var filtered = _._(hash.expected).filter((value: string) => _.include(value, hash.token))
const token = hash.token === 'EOF' ? "'" : `'${hash.token}`;

var filtered = _._(hash.expected).filter((value: string) => _.startsWith(value, token))
.map((value: string) => /^'(.*)'$/.exec(value)[1])
.value();

Expand Down

0 comments on commit 9d14e2d

Please sign in to comment.