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

wozjac / vscode-ui5-api-reference / 9626805498

22 Jun 2024 04:23PM UTC coverage: 73.579%. Remained the same
9626805498

push

github

wozjac
Merge branch 'main' of https://github.com/wozjac/vscode-ui5-api-reference

122 of 172 branches covered (70.93%)

Branch coverage included in aggregate %.

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

54 existing lines in 4 files now uncovered.

357 of 479 relevant lines covered (74.53%)

7.07 hits per line

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

85.58
/src/panelFeatures/contextMenu.ts
1
import { TextEditor, TextDocument } from "vscode";
2

3
//Formats the namespace so we can use it for search
4
export function getNamespace(text: string, document: TextDocument): string | undefined {
1✔
5
  const namespace = text.includes(":") ? text.split(":")[0] : "";
11✔
6
  text = text.includes(":") ? text.split(":")[1] : text;
11✔
7
  const documentText = document.getText();
11✔
8

9
  if (!documentText) {
11!
10
    return;
×
11
  }
12

13
  const documentTextLines = documentText.split("\n");
11✔
14

15
  let xmlns = documentTextLines
11✔
16
    .find((line: string) => {
17
      return namespace === ""
30✔
18
        ? line.includes("xmlns=")
30✔
19
        : line.includes("xmlns") && line.includes(namespace);
9✔
20
    })
21
    ?.trim();
22

23
  if (!xmlns) {
11!
24
    return;
×
25
  }
26

27
  xmlns = xmlns.includes(">") ? xmlns.slice(0, -1) : xmlns;
11!
28
  const regex = new RegExp(namespace === "" ? `xmlns="(.*?)"` : `xmlns:${namespace}="(.*?)"`);
11✔
29
  let matchResult = xmlns.match(regex);
11✔
30

31
  if (!matchResult) {
11!
UNCOV
32
    return;
×
33
  }
34

35
  const match = matchResult[0];
11✔
36
  // eslint-disable-next-line
37
  matchResult = match.match(/\"(.*?)\"/);
11✔
38

39
  if (!matchResult) {
11!
40
    return;
×
41
  }
42

43
  xmlns = matchResult[1];
11✔
44

45
  return `${xmlns}.${text}`;
11✔
46
}
47

48
export function findControl(editor: TextEditor): string | undefined {
1✔
49
  const isLowerCase = (input: string) => {
11✔
50
    return /^[a-z]*$/.test(input);
20✔
51
  };
52

53
  const cursorPosition = editor.selection.active;
11✔
54
  const document = editor.document;
11✔
55
  let line = document.lineAt(cursorPosition.line);
11✔
56
  let text = line.text.trim();
11✔
57

58
  if (text.includes("<")) {
11✔
59
    //If the first character after the < is lowercase, then it's an aggregation
60
    if (
10✔
61
      isLowerCase(text.charAt(1) === "/" ? text.charAt(2) : text.charAt(1)) &&
25✔
62
      text.indexOf(":") === -1
63
        ? true
10✔
64
        : isLowerCase(text.charAt(text.indexOf(":") + 1))
65
    ) {
66
      let foundControl = false;
2✔
67
      let count = 1;
2✔
68
      const navigator = text.charAt(1) === "/" ? "-" : "+";
2✔
69

70
      while (foundControl === false) {
2✔
71
        count = navigator === "+" ? cursorPosition.line - count : cursorPosition.line + count;
2✔
72
        line = document.lineAt(count);
2✔
73
        text = line.text.trim();
2✔
74
        if (
2!
75
          text.includes("<") &&
4✔
76
          !isLowerCase(text.charAt(1) === "/" ? text.charAt(2) : text.charAt(1))
2✔
77
        ) {
78
          foundControl = true;
2✔
79
        } else {
80
          count++;
×
81
        }
82
      }
83
    }
84

85
    //just for good measure, check if it's the end tag
86
    const tagSplit = text.includes("</") ? "</" : "<";
10✔
87
    const endSplit = text.includes(" ") ? " " : text.includes(">") ? ">" : "\n";
10✔
88
    text = text.split(tagSplit)[1].split(endSplit)[0];
10✔
89
  } else {
90
    let count = cursorPosition.line - 1;
1✔
91
    text = "";
1✔
92

93
    while (!text) {
1✔
94
      line = editor.document.lineAt(count);
1✔
95
      text = line.text.trim();
1✔
96

97
      if (text.includes("<")) {
1!
98
        const endSplit = text.includes(">") ? ">" : text.includes(" ") ? " " : "\n";
1!
99
        text = text.split("<")[1].split(endSplit)[0];
1✔
100
      } else {
101
        count = count - 1;
×
102
      }
103
    }
104
  }
105

106
  text = text.includes(">") ? text.slice(0, -1) : text;
11✔
107

108
  return getNamespace(text, document);
11✔
109
}
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