Skip to content

Commit

Permalink
Fix default values for parameter objects & insert semicolon after aut…
Browse files Browse the repository at this point in the history
…ocomplete

The default values inserted when using autocomplete and parameter objects were not correct. for example, when you expect to get the number 0 you would instead get the string "Number".
i changed the code to handle the name and default separately before adding the newlines which did the trick.

Also added semicolons to autocomplete according to issue Mitcheljager#246
The semicolons are inserted only when autocompleting actions. having it add semicolons for other type of values could probably get annoying
  • Loading branch information
Loottoo committed Feb 20, 2024
1 parent 08a4ef0 commit 8de79fc
Show file tree
Hide file tree
Showing 6 changed files with 19,541 additions and 13,136 deletions.
1,774 changes: 1,774 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ group :development, :test do
gem "rspec-rails", "~> 4.0.2"
gem "selenium-webdriver", "~> 4.0"
gem "shoulda-matchers", "~> 4.5"
gem "sqlite3", "1.4.2"
gem "sqlite3", "1.6.1"
# To freeze time and allow time travel for time-sensitive tests
gem "timecop"
gem "webdrivers", "~> 5.0"
Expand Down
7 changes: 5 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,10 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
sqlite3 (1.6.1)
mini_portile2 (~> 2.8.0)
sqlite3 (1.6.1-x64-mingw32)
sqlite3 (1.6.1-x86_64-linux)
sucker_punch (3.0.1)
concurrent-ruby (~> 1.0)
sys-uname (1.2.2)
Expand Down Expand Up @@ -575,7 +578,7 @@ DEPENDENCIES
selenium-webdriver (~> 4.0)
sendgrid-ruby
shoulda-matchers (~> 4.5)
sqlite3 (= 1.4.2)
sqlite3 (= 1.6.1)
sucker_punch
timecop
turbolinks (~> 5)
Expand Down
31 changes: 30 additions & 1 deletion app/javascript/src/components/editor/CodeMirror.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { translationsMap } from "../../stores/translationKeys"
import { getPhraseFromPosition } from "../../utils/parse"
import { tabIndent, getIndentForLine, getIndentCountForText, shouldNextLineBeIndent, autoIndentOnEnter, indentMultilineInserts } from "../../utils/codemirror/indent"
import { get } from "svelte/store"
import debounce from "../../debounce"
const dispatch = createEventDispatcher()
Expand Down Expand Up @@ -70,7 +71,7 @@
]),
EditorView.updateListener.of((transaction) => {
if (transaction.docChanged) {
indentMultilineInserts(view, transaction)
autocompleteFormatting(view, transaction)
updateItem()
}
if (transaction.selectionSet) $editorStates[currentId].selection = view.state.selection
Expand Down Expand Up @@ -165,6 +166,34 @@
}
}
function autocompleteFormatting(view, transaction) {
if (transaction.transactions.every(tr => ["input.complete"].includes(tr.annotation(Transaction.userEvent)))) {
indentMultilineInserts(view, transaction)
insertSemicolon(view, transaction)
}
}
function insertSemicolon(view, transaction) {
const line = view.state.doc.lineAt(transaction.changedRanges[0].fromB)
const phrase = getPhraseFromPosition(line, transaction.changedRanges[0].fromB)
const possibleValues = get(completionsMap).filter(v => v.args_length)
const validValue = possibleValues.find(v => v.label == phrase.text)
if (validValue?.type) {
const insertPosition = view.state.selection.ranges[0].from
if(validValue.type === "function") {
view.dispatch({
changes: { from: insertPosition, insert: `;` },
selection: EditorSelection.create([
EditorSelection.range(insertPosition + 1, insertPosition + 1)
])
})
}
}
}
function click(event) {
if (!event.altKey) return
Expand Down
11 changes: 6 additions & 5 deletions app/javascript/src/components/editor/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@
const useNewlines = params.args_length >= $settings["autocomplete-min-parameter-newlines"]
const apply = v.args.map(a => {
let string = a.default?.toString().toLowerCase().replaceAll(",", "")
if (useParameterObject) string = `${ useNewlines ? "\n\t" : "" }${ a.name }: ${ string }`
const name = toCapitalize(a.name?.toString().toLowerCase())
let defaultValue = a.default?.toString().toLowerCase().replaceAll(",", "")
defaultValue = lowercaseDefaults.includes(defaultValue.toLowerCase()) ?
defaults[toCapitalize(defaultValue)] :
toCapitalize(defaultValue)
if (lowercaseDefaults.includes(string)) return defaults[toCapitalize(string)]
return toCapitalize(string)
return useParameterObject ? `${useNewlines ? "\n\t" : ""}${name}: ${defaultValue}` : defaultValue
})
params.parameter_keys = detail
Expand Down
Loading

0 comments on commit 8de79fc

Please sign in to comment.