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

pascalre / vscode-yaml-sort / 3841722199

pending completion
3841722199

Pull #112

github

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

134 of 167 branches covered (80.24%)

Branch coverage included in aggregate %.

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

382 of 408 relevant lines covered (93.63%)

13.58 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
  getRange(textEditor: TextEditor) {
21
    if (textEditor.selection.isEmpty) {
8✔
22
      return VsCodeAdapter.getFullDocumentRange(textEditor)
4✔
23
    } else {
24
      return VsCodeAdapter.getSelectedRange(textEditor)
4✔
25
    }
26
  }
27

28
  getEdits(textEditor: TextEditor, text: string) {
29
    const range = this.getRange(textEditor)
4✔
30
    return TextEdit.replace(range, text)
4✔
31
  }
32

33
  // have a function that adds/removes the formatter based
34
  // on a configuration setting
35
  registerFormatter(formatter: DocumentFormattingEditProvider) {
36
    let registration: Disposable | undefined
37
    const useAsFormatter = this.settings.getUseAsFormatter()
1✔
38
    if (useAsFormatter && !registration) {
1!
39
      languages.registerDocumentFormattingEditProvider('yaml', formatter)
×
40
    } else if (!useAsFormatter && registration) {
1!
41
      registration.dispose()
×
42
    }
43
  }
44

45
  showMessage(severity: Severity, message: string) {
46
    if (severity === Severity.ERROR) {
7✔
47
      window.showErrorMessage(message)
3✔
48
    } else {
49
      if (this.settings.getNotifySuccess()) {
4!
50
        window.showInformationMessage(message)
4✔
51
      }
52
    }
53
  }
54

55
  static getText(textEditor: TextEditor, range: Range) {
56
    return textEditor.document.getText(range)
4✔
57
  }
58

59
  static getFullDocumentRange(textEditor: TextEditor) {
60
    return new Range(
4✔
61
      new Position(0, 0),
62
      new Position(textEditor.document.lineCount + 1, 0))
63
  }
64

65
  static getSelectedRange(textEditor: TextEditor) {
66
    let endLine = textEditor.selection.end.line
4✔
67
    // if selection ends on the first character on a new line ignore this line
68
    if (textEditor.selection.end.character === 0) {
4✔
69
      endLine--
2✔
70
    }
71

72
    // ensure selection covers whole start and end line
73
    return new Selection(
4✔
74
      textEditor.selection.start.line, 0,
75
      endLine, textEditor.document.lineAt(endLine).range.end.character)
76
  }
77

78
  /**
79
  * Applys edits to a text editor
80
  * @param activeEditor Editor to apply the changes
81
  * @param edits Changes to apply
82
  */
83
  static applyEdits(edit: [TextEdit]) {
84
    if (window.activeTextEditor) {
4!
85
      const workspaceEdit = new WorkspaceEdit()
4✔
86
      workspaceEdit.set(window.activeTextEditor.document.uri, edit)
4✔
87
      workspace.applyEdit(workspaceEdit)
4✔
88
    }
89
  }
90

91
  static getActiveDocument(textEditor: TextEditor) {
92
    return textEditor.document.getText()
3✔
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