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

fix: suggest hyphen in array

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

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

  1. 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

  • check for - array items
  • check for - added test for default snippets with string value in the body property

p-spacek avatar Jul 11 '23 10:07 p-spacek

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

p-spacek avatar Sep 05 '23 11:09 p-spacek

@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 avatar Oct 11 '23 10:10 p-spacek

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

p-spacek avatar Oct 11 '23 14:10 p-spacek

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.

coveralls avatar Oct 13 '23 11:10 coveralls

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.

gorkem avatar Oct 13 '23 12:10 gorkem