Skip to content

Commit

Permalink
Fail to fix some bad completions
Browse files Browse the repository at this point in the history
Try to fix bad completions for Gamepad/Keyboard.get_value by slicing
away already-typed part. Observations:
  Completion is multiple tokens (e.g. when quoted):
    slice is needed to remove already-typed string from completion.
  Completion is single token:
    unsliced is needed or else existing text is replaced with sliced
    completion, effectively deleting the already-typed bit.
Revert to using unsliced completions, as Ace can't seem to decide
between replacing partially typed completions or appending to them, and
I don't know how to programmatically predict which Ace will do.
  • Loading branch information
Hal-9k1 committed Nov 21, 2024
1 parent 4219979 commit 5560462
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/renderer/addEditorAutocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default function addEditorAutocomplete(editor: Ace.Editor) {
) => {
const iter = new TokenIterator(session, pos.row, pos.column);
let token = iter.getCurrentToken();
const tokenIsIdent = () => ['identifier', 'function.support'].includes(token.type);

Check failure on line 59 in src/renderer/addEditorAutocomplete.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Insert `⏎·········`
const firstToken = token;
let canPartialComplete = true;
while (token === undefined || token.value.trim() === '') {
Expand All @@ -68,8 +69,7 @@ export default function addEditorAutocomplete(editor: Ace.Editor) {
if (token.type === 'comment') {
return;
}
console.log(`itoken '${token.value}' type ${token.type}`);
let lastWasIdentifier = token.type === 'identifier';
let lastWasIdentifier = tokenIsIdent();
if (iter.getCurrentTokenRow() !== pos.row) {
canPartialComplete = false;
}
Expand All @@ -88,8 +88,7 @@ export default function addEditorAutocomplete(editor: Ace.Editor) {
if (token === null) {
break;
}
console.log(`token '${token.value}' type ${token.type} lwi ${lastWasIdentifier}`);
if (lastWasIdentifier && (token.type === 'identifier' || token.value.trim() !== token.value)) {
if (lastWasIdentifier && (tokenIsIdent() || token.value.trim() !== token.value)) {

Check failure on line 91 in src/renderer/addEditorAutocomplete.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Replace `lastWasIdentifier·&&·(tokenIsIdent()·||·token.value.trim()·!==·token.value)` with `⏎············lastWasIdentifier·&&⏎············(tokenIsIdent()·||·token.value.trim()·!==·token.value)⏎··········`
break;
}
if (token.type === 'comment' || token.value.trim() === '') {
Expand All @@ -100,7 +99,7 @@ export default function addEditorAutocomplete(editor: Ace.Editor) {
}
buf = token.value.trim() + buf;
posInBuf += token.value.trim().length;
lastWasIdentifier = token.type === 'identifier';
lastWasIdentifier = tokenIsIdent();
}
const beforeCaret = buf.slice(0, posInBuf);
const isContext = beforeCaret.startsWith(ctx);
Expand All @@ -109,10 +108,15 @@ export default function addEditorAutocomplete(editor: Ace.Editor) {
? ((ctx + completion).startsWith(beforeCaret))

Check failure on line 108 in src/renderer/addEditorAutocomplete.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Replace `············?·((ctx·+·completion).startsWith(beforeCaret))` with `····················?·(ctx·+·completion).startsWith(beforeCaret)`
: (ctx === beforeCaret))
.map(caption => {
console.log(`bc '${beforeCaret}' ctx '${ctx}' cap '${caption}' cpc ${canPartialComplete}`);
return {
caption,
value: caption.slice(beforeCaret.length - ctx.length),
// FIXME
// Completion is multiple tokens (e.g. Gamepad.get_value completions): slice is needed
// to remove already-typed string from completion.
// Context is single token: unsliced is needed or else existing text is replaced with
// sliced completion, effectively deleting the already-typed bit.
//value: caption.slice(beforeCaret.length - ctx.length),
value: caption,
meta: 'PiE API',
score: COMP_SCORE,
};
Expand Down

0 comments on commit 5560462

Please sign in to comment.