swagger-editor
swagger-editor copied to clipboard
SwaggerEditor@next: Autocomplete for $ref fields with additional character
From the user:
I've noticed a bug on AsyncApi editor. Autocompletion doesn't work when I write $ref: "here use a letter which occurs in path in your domain" and then I click ctrl+space. Please see attached video
https://user-images.githubusercontent.com/193286/170027747-18869f83-45f5-42f9-a077-ca4c352d53f2.mov
This is interesting corner case. When you start typing $ref: and hit ctrl+space then you get autocomplete suggestions and if you write further characters then the autocomplete items filter them self and highlight them self matching what you wrote.
But...when you start typing $ref: c and hit ctrl+space, then no autocompletion is shown. The expected behavior would be to show autocomplete items already filtered and matched to c character
Adding some related notes:
-
adding
matchOnWordStartOnly: false,in editor options might help, but not sufficient -
regardless of the above it doesn't work when current text and/or returned item starts with
#/or#, -
can be also possibly related with wrong/missing range returned in completion item SEE https://github.com/microsoft/monaco-editor/issues/1889
-
maybe also possibly already filtered out by language service itself, to be investigate
Confirmed that language service doesn't return any completion items. It's an issue within apidom-ls.
Standard usecases like the following have been fixed by replacing unquotedOriginalInsertText?.startsWith(word) with unquotedOriginalInsertText?.includes(word).
$ref: user<cursor>
regardless of the above it doesn't work when current text and/or returned item starts with #/ or #,
@frantuma yes, that is expected. # is control character for starting of the YAML comment. Thus it's dropped from the resulting AST. You have to escape it with single or double quotes to represent the value. Following notations works correctly:
$ref: "#<cursor>"
$ref: "<cursor>#"
$ref: '#<cursor>'
$ref: '<cursor>#'
$ref:<cursor> # comment
The only case that behaves IMHO unexpectedly is the following one:
$ref: <cursor> # comment
Instead of $ref suggestions, it gives us Schema Object fields suggestion.
Upstream [email protected] released with bugfix: https://github.com/swagger-api/apidom/releases/tag/v0.69.3
Fixed in https://github.com/swagger-api/swagger-editor/releases/tag/v5.0.0-alpha.58
@char0n
The only case that behaves IMHO unexpectedly is the following one: $ref:
# comment
not sure if this was fixed somehow as I am not able to reproduce, I am however able to reproduce a similar behaviour by:
ctrl+click on $ref: #/com<cursor> (no results) and then hit left arrow (schema properties appear)
might be worth adding this to own ticket.
regardless of the above it doesn't work when current text and/or returned item starts with #/ or #,
@frantuma yes, that is expected. # is control character for starting of the YAML comment. Thus it's dropped from the resulting AST. You have to escape it with single or double quotes to represent the value. Following notations works correctly:
I understand your point, still (for future reference in case) it might be a better experience for the user to have completion triggered also in case:
$ref: #<cursor> or $ref: #/<cursor> . This might need some "hack" in apidom-ls completion service node interpretation. Possibly also this to be added to own ticket..
Last point not fully related to bug reported in this ticket, it might be good to tweak editor properties as below.
Specifically quickSuggestions: { other: true, strings: true }, seems to help in triggering completion after key press within ref values.
quickSuggestions: { other: true, strings: true },
matchOnWordStartOnly: false,
suggest: {
snippetsPreventQuickSuggestions: false,
showValues: true,
},
not sure if this was fixed somehow as I am not able to reproduce, I am however able to reproduce a similar behaviour by: ctrl+click on $ref: #/com
(no results) and then hit left arrow (schema properties appear) might be worth adding this to own ticket.
Transformed into separate https://github.com/swagger-api/swagger-editor/issues/4108 with Steps Of Reproduction recorded as video.
I understand your point, still (for future reference in case) it might be a better experience for the user to have completion triggered also in case: $ref: #
or $ref: #/ . This might need some "hack" in apidom-ls completion service node interpretation. Possibly also this to be added to own ticket..
Transformed into separate https://github.com/swagger-api/swagger-editor/issues/4109.
Last point not fully related to bug reported in this ticket, it might be good to tweak editor properties as below. Specifically quickSuggestions: { other: true, strings: true }, seems to help in triggering completion after key press within ref values.
Transformed into separate https://github.com/swagger-api/swagger-editor/issues/4110