redhat-developer / yaml-language-server

Language Server for YAML Files
MIT License
1.1k stars 264 forks source link

fix: suggest hyphen in array #901

Open p-spacek opened 1 year ago

p-spacek commented 1 year ago

What does this PR do?

1) - (array item) suggestion was missing for some specific situations, for example: enums. it worked ok for 1st item after a colon, but not for 2nd

after fix:

image

UPDATE I extended this PR because there were related issues, with a tiny update of this original problem, I can fix another 2 problems: 2) auto add - when hyphen is missing

image

choose item will produce incorrect yaml

image

3) The default snippet with a simple string will produce this weird result when the string value is defined in snippet body

image

What issues does this PR fix or reference?

no ref

Is it tested? How?

modified existing added one test for the enum

p-spacek commented 1 year ago

Hello @msivasubramaniaan, can I ask you for a review?

p-spacek commented 1 year ago

@gorkem , I don't think that there should be such a filter/condition because schema

{
          type: 'object',
          properties: {
            references: {
              type: 'array',
              items: {
                enum: ['Test', 'Test2'],
              },
            },
}

doesn't define that items of the array have to be unique. To be honest I am not sure how to define this (unique array items)...

This should be allowed based on the schema

items:
 - Test1
 - Test1
 - Test2

or don't you agree? did I understand you incorrectly?

p-spacek commented 1 year ago

I found another related problem So I converted this PR to a draft I'll try to fix it at once

coveralls commented 1 year ago

Coverage Status

coverage: 83.841% (+0.03%) from 83.813% when pulling 8e4d05f1bf28c2bb7a6070f4aca3444bb047de0d on jigx-com:fix/suggest-hyphen-in-arrays into ed03cbf71ade29ea62b4bcac0d8952195fd6969d on redhat-developer:main.

gorkem commented 1 year ago

Correct, item uniqueness is determined by the schema. The current implementation does not take into account the uniqueItems flag. An improvement to the current implementation would be checking this flag and filtering accordingly. In general, code assist should not suggest values leading to syntax errors, even though it is a trivial fix.