yaml-language-server icon indicating copy to clipboard operation
yaml-language-server copied to clipboard

feat: exclude deprecated schema from autocompletion

Open p-spacek opened this issue 2 years ago • 6 comments

What does this PR do?

exclude deprecated schema from autocompletion useful when you want to exclude some subschemas from autocompletion, but you need it to be there for validation purposes. So you can't just remove it.

"anyOf":[
  {
     "$ref": "schema1",
     "deprecatedMessage": "Deprecated: use schema2 instead"
   },
  {
     "$ref": "schema2",
   }
]

What issues does this PR fix or reference?

no ref

Is it tested? How?

added tests

p-spacek avatar Jan 17 '23 12:01 p-spacek

Coverage Status

Coverage: 83.373% (+0.07%) from 83.304% when pulling 6dc3ca967b040ebd3bda98a9cf39425a631016f8 on jigx-com:feat/exclude-deprecated-schema-from-autocompletion into cf3f79202524ba979f1f4011636b85d08d81bdcb on redhat-developer:main.

coveralls avatar Jan 17 '23 12:01 coveralls

This should be setting to exclude them. Otherwise, LSPs do have a way to mark deprecated code completions as deprecated and we should actually use that mechanism instead of excluding them directly.

gorkem avatar Jan 24 '23 23:01 gorkem

This should be setting to exclude them. Otherwise, LSPs do have a way to mark deprecated code completions as deprecated and we should actually use that mechanism instead of excluding them directly.

Hi @gorkem , Sorry, I am not sure if I understand correctly your thoughts. Can you explain them, please? The previous implementation allows only to exclude properties, not the whole schema.

p-spacek avatar Feb 07 '23 09:02 p-spacek

Deprecated APIs are common in programming languages. Typically language tooling deals with it, not by removing them without notice but by marking them. Deprecated properties can be marked as deprecated by the yaml-language-server using the deprecated hint. #763 is an incomplete implementation in that direction. We can also take it further and introduce a setting that will allow users to select that they do not want deprecated properties to be presented as code completion.

gorkem avatar Feb 25 '23 21:02 gorkem

Oh, I understand now. Sorry for the late reply. So I think that I need doNotSuggest schema property to exclude something from code-completion

Note1: current implementation excludes properties with deprecationMessage https://github.com/redhat-developer/yaml-language-server/blob/main/src/languageservice/services/yamlCompletion.ts#L719 if (typeof propertySchema === 'object' && !propertySchema.deprecationMessage && !propertySchema['doNotSuggest']) {

So I will probably create another fix PR that will finish the doNotSuggest implementation

  • doNotSuggest is implemented only for properties, but it should work also for schemas (value and property completion)

do you agree, @gorkem ?

I won't modify the deprecation functionality at all for now...

  • maybe later as you suggested:
    • cross it out (typescript has the same)
    • some user configuration to define if a completion item should be excluded completely or crossed out

p-spacek avatar Apr 26 '23 11:04 p-spacek

A complete solution would be to enable the deprecated hint (the cross out) and add a setting (not a schema property) to not suggest the deprecated properties. I do not think it is the schema author's decision whether to use a deprecated property or not. Schema author already has done its responsibility by marking it deprecated.

gorkem avatar Apr 27 '23 15:04 gorkem