Skip to content

Commit 6132cb8

Browse files
authored
Merge branch 'main' into yaml-schema-lint
2 parents b2ab311 + 37a7b17 commit 6132cb8

19 files changed

+920
-160
lines changed

.github/workflows/CI.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
uses: coverallsapp/github-action@c7885c00cb7ec0b8f9f5ff3f53cddb980f7a4412 # v2.2.0
7575
with:
7676
github-token: ${{ secrets.GITHUB_TOKEN }}
77+
continue-on-error: true
7778

7879
- name: Publish
7980
if: ${{ success() && runner.os == 'Linux' && github.event_name == 'push' && github.ref == 'refs/heads/main'}}

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
### 1.21.0
2+
- Feat: Enable suppressing diagnostics per-line by adding a `# yaml-language-server-disable` comment [vscode-yaml#666](https://github.com/redhat-developer/vscode-yaml/issues/666)
3+
- Feat: Allow `yaml.validate` and `yaml.format.enable` to be overriden in language-specific settings [#1188](https://github.com/redhat-developer/yaml-language-server/pull/1188)
4+
- Fix: Do not register the extension for templated YAML languages (such as Helm, Jinja, etc.) [vscode-yaml#1204](https://github.com/redhat-developer/vscode-yaml/issues/1204)
5+
- Fix: Handle default booleans and integers properly in required properties completion [vscode-yaml#1205](https://github.com/redhat-developer/vscode-yaml/issues/1205)
6+
- Fix: Prevent infinite `$ref` resolution loops [#1195](https://github.com/redhat-developer/yaml-language-server/issues/1195)
7+
- Fix: Preserve document end marker (`...`) when formatting (by updating prettier to 3.8.1) [vscode-yaml#1211](https://github.com/redhat-developer/vscode-yaml/issues/1211)
8+
- Fix: Don't escape '-' in hover text, since it was breaking links [#1151](https://github.com/redhat-developer/yaml-language-server/issues/1151)
9+
- Fix: Attempt to resolve a schema referenced through a relative `$ref` locally before peforming a remote `$id` lookup [#1186](https://github.com/redhat-developer/yaml-language-server/issues/1184)
10+
- Fix: Improve documentation of `yaml.schemas` setting [vscode-yaml#1207](https://github.com/redhat-developer/vscode-yaml/issues/1207)
11+
12+
Thanks to [Simon Heather](https://github.com/X-Guardian) for your contributions
13+
114
### 1.20.0
215
- Feat: Support JSON Schema 2019-09 and 2020-12 [#478](https://github.com/redhat-developer/yaml-language-server/issues/478), [vscode-yaml#1122](https://github.com/redhat-developer/vscode-yaml/issues/1122), [#823](https://github.com/redhat-developer/yaml-language-server/issues/823)
316
- Feat: Support drafts 2019-09 and 2020-12 when validating a referenced JSON schema using AJV [#1164](https://github.com/redhat-developer/yaml-language-server/pull/1164)

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,33 @@ The following settings are supported:
5656
- `yaml.style.flowSequence` : Forbids flow style sequences if set to `forbid`
5757
- `yaml.keyOrdering` : Enforces alphabetical ordering of keys in mappings when set to `true`. Default is `false`
5858

59+
## Suppressing diagnostics
60+
61+
You can suppress specific validation warnings on a per-line basis by adding a `# yaml-language-server-disable` comment on the line immediately before the one producing the diagnostic.
62+
63+
### Suppress all diagnostics on a line
64+
65+
```yaml
66+
# yaml-language-server-disable
67+
version: 123
68+
```
69+
70+
### Suppress only specific diagnostics
71+
72+
Provide one or more message substrings (comma-separated, case-insensitive). Only diagnostics whose message contains a matching substring will be suppressed; the rest are kept.
73+
74+
```yaml
75+
# yaml-language-server-disable Incorrect type
76+
version: 123
77+
```
78+
79+
```yaml
80+
# yaml-language-server-disable Incorrect type, not accepted
81+
version: 123
82+
```
83+
84+
The substrings are matched against the diagnostic message text reported by the language server.
85+
5986
##### Adding custom tags
6087
6188
In order to use the custom tags in your YAML file you need to first specify the custom tags in the setting of your code editor. For example, we can have the following custom tags:
@@ -260,6 +287,12 @@ or absolute path:
260287
# yaml-language-server: $schema=/absolute/path/to/schema
261288
```
262289

290+
or IntelliJ compatible format:
291+
292+
```yaml
293+
# $schema: <urlOrPathToTheSchema>
294+
```
295+
263296
### Schema priority
264297

265298
The following is the priority of schema association in highest to lowest priority:

package-lock.json

Lines changed: 17 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "yaml-language-server",
33
"description": "YAML language server",
4-
"version": "1.20.1",
4+
"version": "1.22.0",
55
"author": "Red Hat",
66
"license": "MIT",
77
"contributors": [
@@ -30,7 +30,7 @@
3030
"@vscode/l10n": "^0.0.18",
3131
"ajv": "^8.17.1",
3232
"ajv-draft-04": "^1.0.0",
33-
"prettier": "^3.5.0",
33+
"prettier": "^3.8.1",
3434
"request-light": "^0.5.7",
3535
"vscode-json-languageservice": "4.1.8",
3636
"vscode-languageserver": "^9.0.0",
@@ -53,8 +53,6 @@
5353
"eslint-config-prettier": "^9.0.0",
5454
"eslint-plugin-import": "^2.26.0",
5555
"eslint-plugin-prettier": "^5.0.0",
56-
"http-proxy-agent": "^5.0.0",
57-
"https-proxy-agent": "^5.0.0",
5856
"mocha": "11.7.1",
5957
"mocha-lcov-reporter": "^1.3.0",
6058
"nyc": "^15.1.0",
@@ -69,9 +67,9 @@
6967
"clean": "rimraf out/server && rimraf lib",
7068
"compile": "tsc -p .",
7169
"watch": "tsc --watch -p .",
72-
"test": "mocha --require ts-node/register --timeout 5000 --ui bdd ./test/*.test.ts",
73-
"coverage": "nyc mocha --require ts-node/register --timeout 5000 --require source-map-support/register --recursive --ui bdd ./test/*.test.ts",
74-
"coveralls": "nyc --reporter=lcov --reporter=text mocha --timeout 5000 --require ts-node/register --require source-map-support/register --recursive --ui bdd ./test/*.test.ts",
70+
"test": "mocha --require ts-node/register --timeout 10000 --ui bdd ./test/*.test.ts",
71+
"coverage": "nyc mocha --require ts-node/register --timeout 10000 --require source-map-support/register --recursive --ui bdd ./test/*.test.ts",
72+
"coveralls": "nyc --reporter=lcov --reporter=text mocha --timeout 10000 --require ts-node/register --require source-map-support/register --recursive --ui bdd ./test/*.test.ts",
7573
"lint": "eslint --max-warnings 0 -c .eslintrc.js --ext .ts src test",
7674
"lint-ci": "eslint --max-warnings 0 -c .eslintrc.js -f @microsoft/eslint-formatter-sarif -o eslint-result.sarif --ext .ts src test",
7775
"prettier-fix": "npm run prettier --write .",

src/languageserver/handlers/settingsHandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class SettingsHandler {
4040
const config = await this.connection.workspace.getConfiguration([
4141
{ section: 'yaml' },
4242
{ section: 'http' },
43-
{ section: '[yaml]', scopeUri: 'null' },
43+
{ section: '[yaml]' },
4444
{ section: 'editor' },
4545
{ section: 'files' },
4646
]);

src/languageservice/services/crdUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function autoDetectKubernetesSchemaFromDocument(
3737
})
3838
.filter((ref) => ref)
3939
.map((ref) => ref.replace('_definitions.json#/definitions/', '').toLowerCase());
40-
const groupWithoutK8sIO = group.replace('.k8s.io', '');
40+
const groupWithoutK8sIO = group.replace('.k8s.io', '').replace('rbac.authorization', 'rbac');
4141
const k8sTypeName = `io.k8s.api.${groupWithoutK8sIO.toLowerCase()}.${version.toLowerCase()}.${kind.toLowerCase()}`;
4242

4343
if (kubernetesBuildIns.includes(k8sTypeName)) {

src/languageservice/services/modelineUtil.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@ export function getSchemaFromModeline(doc: SingleYAMLDocument | JSONDocument): s
1717
return isModeline(lineComment);
1818
});
1919
if (yamlLanguageServerModeline != undefined) {
20-
const schemaMatchs = yamlLanguageServerModeline.match(/\$schema=\S+/g);
21-
if (schemaMatchs !== null && schemaMatchs.length >= 1) {
22-
if (schemaMatchs.length >= 2) {
23-
console.log(
24-
'Several $schema attributes have been found on the yaml-language-server modeline. The first one will be picked.'
25-
);
26-
}
27-
return schemaMatchs[0].substring('$schema='.length);
20+
const schemaMatches = yamlLanguageServerModeline.match(/\$schema(?:=|:\s*)(\S+)/);
21+
if (schemaMatches !== null && schemaMatches.length === 2) {
22+
return schemaMatches[1];
2823
}
2924
}
3025
}
3126
return undefined;
3227
}
3328

3429
export function isModeline(lineText: string): boolean {
35-
const matchModeline = lineText.match(/^#\s+yaml-language-server\s*:/g);
30+
const matchModeline = lineText.match(/^#\s+(?:yaml-language-server\s*:|\$schema:)/g);
3631
return matchModeline !== null && matchModeline.length === 1;
3732
}

src/languageservice/services/yamlCompletion.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -336,21 +336,24 @@ export class YamlCompletion {
336336
}
337337

338338
if (isModeline(lineContent) || isInComment(doc.tokens, offset)) {
339-
const schemaIndex = lineContent.indexOf('$schema=');
340-
if (schemaIndex !== -1 && schemaIndex + '$schema='.length <= position.character) {
341-
this.schemaService.getAllSchemas().forEach((schema) => {
342-
const schemaIdCompletion: CompletionItem = {
343-
kind: CompletionItemKind.Constant,
344-
label: schema.name ?? schema.uri,
345-
detail: schema.description,
346-
insertText: schema.uri,
347-
insertTextFormat: InsertTextFormat.PlainText,
348-
insertTextMode: InsertTextMode.asIs,
349-
};
350-
result.items.push(schemaIdCompletion);
351-
});
339+
const schemaMatch = lineContent.match(/\$schema[=:]/);
340+
if (schemaMatch) {
341+
const schemaIndex = schemaMatch.index;
342+
if (schemaIndex + schemaMatch[0].length <= position.character) {
343+
this.schemaService.getAllSchemas().forEach((schema) => {
344+
const schemaIdCompletion: CompletionItem = {
345+
kind: CompletionItemKind.Constant,
346+
label: schema.name ?? schema.uri,
347+
detail: schema.description,
348+
insertText: schema.uri,
349+
insertTextFormat: InsertTextFormat.PlainText,
350+
insertTextMode: InsertTextMode.asIs,
351+
};
352+
result.items.push(schemaIdCompletion);
353+
});
354+
}
355+
return result;
352356
}
353-
return result;
354357
}
355358

356359
if (!schema || schema.errors.length) {
@@ -1164,8 +1167,8 @@ export class YamlCompletion {
11641167
case 'number':
11651168
case 'integer':
11661169
case 'anyOf': {
1167-
let value = propertySchema.default || propertySchema.const;
1168-
if (value) {
1170+
let value = propertySchema.default !== undefined ? propertySchema.default : propertySchema.const;
1171+
if (value !== undefined) {
11691172
if (type === 'string') {
11701173
value = toYamlStringScalar(value);
11711174
}

0 commit comments

Comments
 (0)