Skip to content

Commit

Permalink
[dagit] Fix CodeMirror show-hint error (#7334)
Browse files Browse the repository at this point in the history
## Summary

There is an error within the CodeMirror show-hint addon that fires on an empty Launchpad. This appears to be because we aren't providing `from` and `to` values in the return value for the `hint` helper function, and they are expected to be there. Add them.

## Test Plan

View Launchpad, clear out editor config. Start typing in the empty editor, verify that hint suggestions render properly and that there are no JS errors in the console.
  • Loading branch information
hellendag committed Apr 7, 2022
1 parent e80494f commit 98c41b4
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,7 @@ CodeMirror.registerHelper(
options: {
schema?: ConfigEditorRunConfigSchemaFragment;
},
): {list: Array<CodemirrorHint>} => {
if (!options.schema) {
return {list: []};
}

): {list: Array<CodemirrorHint>; from: CodemirrorLocation; to: CodemirrorLocation} => {
const {
cursor,
context,
Expand All @@ -321,8 +317,16 @@ CodeMirror.registerHelper(
searchString,
prevToken,
} = expandAutocompletionContextAtCursor(editor);

const from = {line: cursor.line, ch: start};
const to = {line: cursor.line, ch: token.end};

if (!options.schema) {
return {list: [], from, to};
}

if (!context) {
return {list: []};
return {list: [], from, to};
}

// Since writing meaningful tests for this functionality is difficult given a) no jsdom
Expand Down Expand Up @@ -433,8 +437,8 @@ CodeMirror.registerHelper(
}
el.appendChild(div);
},
from: {line: cursor.line, ch: start},
to: {line: cursor.line, ch: token.end},
from,
to,
});

// Calculate if this is on a new-line child of a scalar union type, as an indication that we
Expand All @@ -458,6 +462,8 @@ CodeMirror.registerHelper(
field.description,
),
),
from,
to,
};
}

Expand All @@ -470,6 +476,8 @@ CodeMirror.registerHelper(
list: context.type.values
.filter((val) => val.value.startsWith(searchWithoutQuotes))
.map((val) => buildSuggestion(val.value, `"${val.value}"`, null)),
from,
to,
};
}

Expand All @@ -479,6 +487,8 @@ CodeMirror.registerHelper(
list: ['True', 'False']
.filter((val) => val.startsWith(searchString))
.map((val) => buildSuggestion(val, val, null)),
from,
to,
};
}

Expand Down Expand Up @@ -513,10 +523,10 @@ CodeMirror.registerHelper(
);
}

return {list: [...scalarSuggestions, ...nonScalarSuggestions]};
return {list: [...scalarSuggestions, ...nonScalarSuggestions], from, to};
}

return {list: []};
return {list: [], from, to};
},
);

Expand Down

0 comments on commit 98c41b4

Please sign in to comment.