forked from microsoft/vscode-java-dependency
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.ts
More file actions
134 lines (107 loc) · 5.61 KB
/
Copy pathsettings.ts
File metadata and controls
134 lines (107 loc) · 5.61 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import {
commands, ConfigurationChangeEvent, ExtensionContext,
workspace, WorkspaceConfiguration,
} from "vscode";
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
import { Commands } from "./commands";
import { syncHandler } from "./syncHandler";
export class Settings {
public static initialize(context: ExtensionContext): void {
context.subscriptions.push(workspace.onDidChangeConfiguration((e: ConfigurationChangeEvent) => {
if (!e.affectsConfiguration("java.dependency")) {
return;
}
const oldConfig = this._dependencyConfig;
this._dependencyConfig = workspace.getConfiguration("java.dependency");
for (const listener of this._configurationListeners) {
listener(this._dependencyConfig, oldConfig);
}
}));
this.registerConfigurationListener((updatedConfig, oldConfig) => {
if (updatedConfig.showMembers !== oldConfig.showMembers
|| updatedConfig.packagePresentation !== oldConfig.packagePresentation
|| (updatedConfig.syncWithFolderExplorer !== oldConfig.syncWithFolderExplorer
&& updatedConfig.syncWithFolderExplorer)) {
commands.executeCommand(Commands.VIEW_PACKAGE_INTERNAL_REFRESH);
} else if (updatedConfig.autoRefresh !== oldConfig.autoRefresh) {
syncHandler.updateFileWatcher(updatedConfig.autoRefresh);
}
});
syncHandler.updateFileWatcher(Settings.autoRefresh());
context.subscriptions.push({ dispose: () => { this._configurationListeners = []; } });
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_LINKWITHFOLDER, Settings.linkWithFolderCommand));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_UNLINKWITHFOLDER, Settings.unlinkWithFolderCommand));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_CHANGETOFLATPACKAGEVIEW,
Settings.changeToFlatPackageView));
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_CHANGETOHIERARCHICALPACKAGEVIEW,
Settings.changeToHierarchicalPackageView));
}
public static registerConfigurationListener(listener: Listener) {
this._configurationListeners.push(listener);
}
public static linkWithFolderCommand(): void {
workspace.getConfiguration().update("java.dependency.syncWithFolderExplorer", true, false);
}
public static unlinkWithFolderCommand(): void {
workspace.getConfiguration().update("java.dependency.syncWithFolderExplorer", false, false);
}
public static changeToFlatPackageView(): void {
workspace.getConfiguration().update("java.dependency.packagePresentation", PackagePresentation.Flat, false);
}
public static changeToHierarchicalPackageView(): void {
workspace.getConfiguration().update("java.dependency.packagePresentation", PackagePresentation.Hierarchical, false);
}
public static updateReferencedLibraries(libraries: IReferencedLibraries): void {
let updateSetting: string[] | Partial<IReferencedLibraries> = {
include: libraries.include,
exclude: libraries.exclude.length > 0 ? libraries.exclude : undefined,
sources: Object.keys(libraries.sources).length > 0 ? libraries.sources : undefined,
};
if (!updateSetting.exclude && !updateSetting.sources) {
updateSetting = libraries.include;
}
workspace.getConfiguration().update("java.project.referencedLibraries", updateSetting);
}
public static referencedLibraries(): IReferencedLibraries {
const setting = workspace.getConfiguration("java.project").get<string[] | Partial<IReferencedLibraries>>("referencedLibraries");
const defaultSetting: IReferencedLibraries = { include: [], exclude: [], sources: {} };
if (Array.isArray(setting)) {
return { ...defaultSetting, include: setting };
} else {
return { ...defaultSetting, ...setting };
}
}
public static showMembers(): boolean {
return this._dependencyConfig.get("showMembers", false);
}
public static autoRefresh(): boolean {
return this._dependencyConfig.get("autoRefresh", true);
}
public static syncWithFolderExplorer(): boolean {
return this._dependencyConfig.get("syncWithFolderExplorer", true);
}
public static isHierarchicalView(): boolean {
return this._dependencyConfig.get("packagePresentation") === PackagePresentation.Hierarchical;
}
public static refreshDelay(): number {
return this._dependencyConfig.get("refreshDelay", 2000);
}
public static getExportJarTargetPath(): string {
// tslint:disable-next-line: no-invalid-template-strings
return workspace.getConfiguration("java.project.exportJar").get<string>("targetPath", "${workspaceFolder}/${workspaceFolderBasename}.jar");
}
private static _dependencyConfig: WorkspaceConfiguration = workspace.getConfiguration("java.dependency");
private static _configurationListeners: Listener[] = [];
}
enum PackagePresentation {
Flat = "flat",
Hierarchical = "hierarchical",
}
type Listener = (updatedConfig: WorkspaceConfiguration, oldConfig: WorkspaceConfiguration) => void;
export interface IReferencedLibraries {
include: string[];
exclude: string[];
sources: { [binary: string]: string };
}