Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions generate-example.nu
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env nu
$nu.scope.commands |
where is_builtin and (not $it.is_extern) |
get -i examples |
each {|r| $r.example? | append (char nl)} |
flatten | save -f example.nu

$nu.scope.commands |
where is_builtin and (not $it.is_extern) |
get --ignore-errors examples |
each {$it.example? | append (char nl)} |
flatten |
save --force example.nu
78 changes: 42 additions & 36 deletions generate-patterns.nu
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,35 @@
def sort-by-length [
column: string
] {
insert length {get $column|str length}
|sort-by -r length
|reject length
insert length {get $column | str length} |
sort-by --reverse length |
reject length
}

# generate combined regex for all single word commands
def match-for-single [
commands:record
commands: record
] {
'\b(' + ($commands|where ($it.subcommands|length) == 1|sort-by-length name|get name|str collect '|'|str replace -a -s '?' '\?') + ')\b'
'\b(' + ($commands |
where ($it.subcommands | length) == 1 |
sort-by-length name |
get name |
str join '|' |
str replace --all --string '?' '\?') + ')\b'
}

# generate list of regexes for every two word command name
def match-for-double [
commands: record
] {
$commands
|where ($it.subcommands|length) > 0 and ($it.subcommands.second-word|all $it != '')|each {|x|
'\b' + $x.name + '(\s' + ($x.subcommands.second-word|compact|str collect '|\s') + ')\b'
}
$commands |
where ($it.subcommands | length) > 0 and ($it.subcommands.second-word |
all {$it != ''}) |
each {
'\b' + $it.name + '(\s' + ($it.subcommands.second-word |
compact |
str join '|\s') + ')\b'
}
}

# returns regexes for all commands, both single and double word single-word append is conditional because some letters only have two word commands e.g 'q'
Expand All @@ -37,41 +46,38 @@ def generate-matches [
}
}

let patterns = (
$nu.scope.commands
|where is_builtin == true and is_extern == false
|get name
|split column ' ' first-word second-word
|default '' second-word
|uniq
|upsert category {|x|
let first_letter = ($x.first-word|split chars|get 0)
if $x.second-word == '' {
let patterns = ($nu.scope.commands |
where is_builtin == true and is_extern == false |
get name |
split column ' ' first-word second-word |
default '' second-word |
uniq |
upsert category {
let first_letter = ($it.first-word | split chars | get 0)
if $it.second-word == '' {
$"($first_letter)"
} else {
$"($first_letter)_sub"
}
}
|group-by category
|transpose category commands
|upsert commands {
get commands
|group-by first-word
|transpose name subcommands
}
|reverse
|each {|category|
generate-matches $category
|each {|match|
} |
group-by category |
transpose category commands |
upsert commands {
get commands |group-by first-word |transpose name subcommands
} |
reverse |
each {|category|
generate-matches $category |
each {|match|
{name: $"keyword.other.($category.category)", match: $match}
}
}
|flatten
} |
flatten
)

open syntaxes/nushell.tmLanguage.json
|update repository.keywords.patterns $patterns
|save syntaxes/nushell.tmLanguage.json
open syntaxes/nushell.tmLanguage.json |
update repository.keywords.patterns $patterns |
save syntaxes/nushell.tmLanguage.json

# TODO: don't allow keywords that have their own definition to be included keyword.other.blah

Expand Down
6 changes: 3 additions & 3 deletions scripts/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

export CODE_TESTS_PATH="$(pwd)/client/out/test"
export CODE_TESTS_WORKSPACE="$(pwd)/client/testFixture"
export CODE_TESTS_PATH="$PWD/client/out/test"
export CODE_TESTS_WORKSPACE="$PWD/client/testFixture"

node "$(pwd)/client/out/test/runTest"
node "$PWD/client/out/test/runTest"