• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pascalre / vscode-yaml-sort / 44698415144

20 Nov 2026 07:54AM UTC coverage: 95.756% (+73.7%) from 22.015%
44698415144

push

github

web-flow
Merge pull request #327 from pascalre/feat/coverage-and-settings

fix: restore coverage measurement, read settings per document, activate on demand

164 of 179 branches covered (91.62%)

Branch coverage included in aggregate %.

67 of 67 new or added lines in 9 files covered. (100.0%)

1 existing line in 1 file now uncovered.

558 of 575 relevant lines covered (97.04%)

74.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.61
/src/controller/controller.ts
1
import { TextEdit, TextEditor, window } from "vscode"
1 ✔
2

3
import { formatDocuments, sortDocuments } from "./document-transformer"
1 ✔
4
import { JsYamlAdapter } from "../adapter/js-yaml-adapter"
1 ✔
5
import { Severity, VsCodeAdapter } from "../adapter/vs-code-adapter"
1 ✔
6
import { Settings } from "../settings"
1 ✔
7
import { ErrorUtil } from "../util/error-util"
1 ✔
8
import { YamlUtil } from "../util/yaml-util"
1 ✔
9

10
export class Controller {
1 ✔
11
  editor: TextEditor
12
  settings: Settings
13
  yamlutil: YamlUtil
14
  jsyamladapter: JsYamlAdapter
15
  vscodeadapter: VsCodeAdapter
16
  errorutil = new ErrorUtil()
7 ✔
17

18
  constructor() {
19
    if (!window.activeTextEditor) {
7 !
UNCOV
20
      throw new Error("No texteditor is active")
×
21
    }
22
    this.editor = window.activeTextEditor
7 ✔
23
    // one snapshot of the settings that apply to the edited document
24
    this.settings = Settings.forDocument(this.editor.document)
7 ✔
25
    this.yamlutil = new YamlUtil(this.settings)
7 ✔
26
    this.jsyamladapter = new JsYamlAdapter(this.settings)
7 ✔
27
    this.vscodeadapter = new VsCodeAdapter(this.settings)
7 ✔
28
  }
29

30
  validateYamlWrapper(): boolean {
31
    const text = VsCodeAdapter.getActiveDocument(this.editor)
2 ✔
32
    try {
2 ✔
33
      this.jsyamladapter.validateYaml(text)
2 ✔
34
      this.vscodeadapter.showMessage(Severity.INFO, "YAML is valid.")
2 ✔
35
      return true
2 ✔
36
    } catch (error) {
37
      this.errorutil.handleError(error)
×
38
    }
39
    return false
×
40
  }
41

42
  formatYamlWrapper(): TextEdit[] {
43
    const newText = formatDocuments(VsCodeAdapter.getActiveDocument(this.editor), this.yamlutil)
2 ✔
44
    if (newText === null) {
2 !
45
      return []
×
46
    }
47
    const edits = this.applyEdits(newText)
2 ✔
48
    // only the command reports success, the formatter stays silent (see #65)
49
    this.vscodeadapter.showMessage(Severity.INFO, "Yaml formatted successfully")
2 ✔
50
    return edits
2 ✔
51
  }
52

53
  applyEdits(text: string) {
54
    const edits = VsCodeAdapter.getEdits(this.editor, text)
4 ✔
55
    VsCodeAdapter.applyEdits([edits])
4 ✔
56
    return [edits]
4 ✔
57
  }
58

59
  sortYamlWrapper(customSort = 0): TextEdit[] {
3 ✔
60
    const text = VsCodeAdapter.getText(this.editor, VsCodeAdapter.getRange(this.editor))
3 ✔
61
    let newText: string | null
62
    try {
3 ✔
63
      newText = sortDocuments(text, { customSort, isSelection: !this.editor.selection.isEmpty }, this.yamlutil)
3 ✔
64
    } catch (error) {
65
      this.errorutil.handleError(error)
1 ✔
66
      return []
1 ✔
67
    }
68
    if (newText === null) {
2 !
69
      return []
×
70
    }
71
    const edits = this.applyEdits(newText)
2 ✔
72
    this.vscodeadapter.showMessage(Severity.INFO, "Keys resorted successfully")
2 ✔
73
    return edits
2 ✔
74
  }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc