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

pascalre / vscode-yaml-sort / 3842156955

pending completion
3842156955

Pull #112

github

GitHub
Merge f8ccca012 into 89a7c4d0e
Pull Request #112: 110 add configuration for deepsourceio

131 of 163 branches covered (80.37%)

Branch coverage included in aggregate %.

113 of 113 new or added lines in 8 files covered. (100.0%)

383 of 408 relevant lines covered (93.87%)

13.54 hits per line

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

87.04
/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"
3✔
10
  settings: Settings
11

12
  constructor(settings = new Settings()) {
3✔
13
    this.settings = settings
3✔
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.getUseAsFormatter()
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) {
7✔
34
      window.showErrorMessage(message)
3✔
35
    } else {
36
      if (this.settings.getNotifySuccess()) {
4!
37
        window.showInformationMessage(message)
4✔
38
      }
39
    }
40
  }
41

42
  static getText(textEditor: TextEditor, range: Range) {
43
    return textEditor.document.getText(range)
4✔
44
  }
45

46
  static getFullDocumentRange(textEditor: TextEditor) {
47
    return new Range(
4✔
48
      new Position(0, 0),
49
      new Position(textEditor.document.lineCount + 1, 0))
50
  }
51

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

59
    // ensure selection covers whole start and end line
60
    return new Selection(
4✔
61
      textEditor.selection.start.line, 0,
62
      endLine, textEditor.document.lineAt(endLine).range.end.character)
63
  }
64

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

78
  static getActiveDocument(textEditor: TextEditor) {
79
    return textEditor.document.getText()
3✔
80
  }
81

82
  static getRange(textEditor: TextEditor) {
83
    if (textEditor.selection.isEmpty) {
8✔
84
      return VsCodeAdapter.getFullDocumentRange(textEditor)
4✔
85
    } else {
86
      return VsCodeAdapter.getSelectedRange(textEditor)
4✔
87
    }
88
  }
89

90
  static getEdits(textEditor: TextEditor, text: string) {
91
    const range = VsCodeAdapter.getRange(textEditor)
4✔
92
    return TextEdit.replace(range, text)
4✔
93
  }
94

95
}
96

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