forked from microsoft/vscode-java-dependency
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.ts
More file actions
116 lines (94 loc) · 3.55 KB
/
Copy pathutility.ts
File metadata and controls
116 lines (94 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { Uri, window, workspace, WorkspaceFolder } from "vscode";
import { setUserError } from "vscode-extension-telemetry-wrapper";
import { INodeData } from "./java/nodeData";
import { languageServerApiManager } from "./languageServerApi/languageServerApiManager";
export class Utility {
public static getDefaultWorkspaceFolder(): WorkspaceFolder | undefined {
if (workspace.workspaceFolders === undefined) {
return undefined;
}
if (workspace.workspaceFolders.length === 1) {
return workspace.workspaceFolders[0];
}
if (window.activeTextEditor) {
const activeWorkspaceFolder: WorkspaceFolder | undefined =
workspace.getWorkspaceFolder(window.activeTextEditor.document.uri);
return activeWorkspaceFolder;
}
return undefined;
}
public static async isRevealable(uri: Uri): Promise<boolean> {
if (!SUPPORTED_URI_SCHEMES.includes(uri.scheme)) {
return false;
}
if (uri.scheme === "file" && !workspace.getWorkspaceFolder(uri)) {
return false;
}
return languageServerApiManager.ready();
}
}
export class EventCounter {
public static dict: {[key: string]: number} = {};
public static increase(event: string) {
const count = this.dict[event] ?? 0;
this.dict[event] = count + 1;
}
}
export class UserError extends Error {
public context: ITroubleshootingMessage;
constructor(context: ITroubleshootingMessage) {
super(context.message);
this.context = context;
setUserError(this);
}
}
interface IProperties {
[key: string]: string;
}
interface ILoggingMessage {
message: string;
type?: Type;
details?: IProperties;
}
interface ITroubleshootingMessage extends ILoggingMessage {
anchor?: string;
}
export enum Type {
EXCEPTION = "exception",
USAGEDATA = "usageData",
USAGEERROR = "usageError",
ACTIVATEEXTENSION = "activateExtension", // TODO: Activation belongs to usage data, remove this category.
}
const keywords: Set<string> = new Set([
"abstract", "default", "if", "private", "this", "boolean", "do", "implements", "protected", "throw", "break", "double", "import",
"public", "throws", "byte", "else", "instanceof", "return", "transient", "case", "extends", "int", "short", "try", "catch", "final",
"interface", "static", "void", "char", "finally", "long", "strictfp", "volatile", "class", "float", "native", "super", "while",
"const", "for", "new", "switch", "continue", "goto", "package", "synchronized", "true", "false", "null", "assert", "enum",
]);
const SUPPORTED_URI_SCHEMES: string[] = ["file", "jdt"];
export function isKeyword(identifier: string): boolean {
return keywords.has(identifier);
}
const identifierRegExp: RegExp = /^([a-zA-Z_$][a-zA-Z\d_$]*)$/;
export function isJavaIdentifier(identifier: string): boolean {
return identifierRegExp.test(identifier);
}
export function isTest(nodeData: INodeData | undefined): boolean {
if (!nodeData) {
return false;
}
if (nodeData.metaData?.test === "true") {
return true;
}
const mavenScope: string = nodeData.metaData?.["maven.scope"] || "";
if (mavenScope.toLocaleLowerCase().includes("test")) {
return true;
}
const gradleScope: string = nodeData.metaData?.gradle_scope || "";
if (gradleScope.toLocaleLowerCase().includes("test")) {
return true;
}
return false;
}