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

pascalre / vscode-yaml-sort / 4138967953

pending completion
4138967953

push

github

Pascal Reitermann
Merge tag '6.3.0'

141 of 166 branches covered (84.94%)

Branch coverage included in aggregate %.

444 of 474 relevant lines covered (93.67%)

35.34 hits per line

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

89.09
/src/adapter/vs-code-adapter.ts
1
import { workspace, TextEditor, Range, Position, Selection, TextEdit, WorkspaceEdit, window, DocumentFormattingEditProvider, languages, Disposable }  from "vscode"
1✔
2
import { Settings } from "../settings"
1✔
3

4
export enum Severity {
1✔
5
  INFO, ERROR
1✔
6
}
7

8
export class VsCodeAdapter {
1✔
9
  section = "vscode-yaml-sort"
60✔
10
  settings: Settings
11

12
  constructor(settings = new Settings()) {
60✔
13
    this.settings = settings
60✔
14
  }
15

16
  getProperty(property: string) {
17
    return workspace.getConfiguration().get(`${this.section}.${property}`)
1✔
18
  }
19

20
  // have a function that adds/removes the formatter based
21
  // on a configuration setting
22
  registerFormatter(formatter: DocumentFormattingEditProvider) {
23
    let registration: Disposable | undefined
24
    const useAsFormatter = this.settings.useAsFormatter
1✔
25
    if (useAsFormatter && !registration) {
1!
26
      languages.registerDocumentFormattingEditProvider('yaml', formatter)
×
27
    } else if (!useAsFormatter && registration) {
1!
28
      registration.dispose()
×
29
    }
30
  }
31

32
  showMessage(severity: Severity, message: string) {
33
    if (severity === Severity.ERROR) {
16✔
34
      window.showErrorMessage(message)
6✔
35
    } else {
36
      this.notify(message)
10✔
37
    }
38
  }
39

40
  notify(message: string) {
41
    if (this.settings.notifySuccess) {
12✔
42
      window.showInformationMessage(message)
11✔
43
    }
44
  }
45

46
  static getText(textEditor: TextEditor, range: Range) {
47
    return textEditor.document.getText(range)
4✔
48
  }
49

50
  static getFullDocumentRange(textEditor: TextEditor) {
51
    return new Range(
4✔
52
      new Position(0, 0),
53
      new Position(textEditor.document.lineCount + 1, 0))
54
  }
55

56
  static getSelectedRange(textEditor: TextEditor) {
57
    let endLine = textEditor.selection.end.line
4✔
58
    // if selection ends on the first character on a new line ignore this line
59
    if (textEditor.selection.end.character === 0) {
4✔
60
      endLine--
2✔
61
    }
62

63
    // ensure selection covers whole start and end line
64
    return new Selection(
4✔
65
      textEditor.selection.start.line, 0,
66
      endLine, textEditor.document.lineAt(endLine).range.end.character)
67
  }
68

69
  /**
70
  * Applys edits to a text editor
71
  * @param activeEditor Editor to apply the changes
72
  * @param edits Changes to apply
73
  */
74
  static applyEdits(edit: [TextEdit]) {
75
    if (window.activeTextEditor) {
4!
76
      const workspaceEdit = new WorkspaceEdit()
4✔
77
      workspaceEdit.set(window.activeTextEditor.document.uri, edit)
4✔
78
      workspace.applyEdit(workspaceEdit)
4✔
79
    }
80
  }
81

82
  static getActiveDocument(textEditor: TextEditor) {
83
    return textEditor.document.getText()
5✔
84
  }
85

86
  static getRange(textEditor: TextEditor) {
87
    if (textEditor.selection.isEmpty) {
8✔
88
      return VsCodeAdapter.getFullDocumentRange(textEditor)
4✔
89
    } else {
90
      return VsCodeAdapter.getSelectedRange(textEditor)
4✔
91
    }
92
  }
93

94
  static getEdits(textEditor: TextEditor, text: string) {
95
    const range = VsCodeAdapter.getRange(textEditor)
4✔
96
    return TextEdit.replace(range, text)
4✔
97
  }
98

99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc