forked from eclipse-lsp4e/lsp4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSPPlugin.java
More file actions
144 lines (127 loc) · 4.85 KB
/
DSPPlugin.java
File metadata and controls
144 lines (127 loc) · 4.85 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
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
* Copyright (c) 2017, 2018 Kichwa Coders Ltd. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.lsp4e.debug;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class DSPPlugin extends AbstractUIPlugin {
public static final boolean DEBUG = Platform.getDebugBoolean("org.eclipse.lsp4e.debug/debug"); //$NON-NLS-1$
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.lsp4e.debug"; //$NON-NLS-1$
// Unique identifier for the DSP debug model launch config
public static final String ID_DSP_DEBUG_MODEL = "org.eclipse.lsp4e.debug.model";
// Launch configuration attribute keys
/** String, one of {@link #DSP_MODE_LAUNCH} or {@link #DSP_MODE_CONNECT} */
public static final String ATTR_DSP_MODE = ID_DSP_DEBUG_MODEL + ".ATTR_DSP_MODE";
public static final String DSP_MODE_LAUNCH = "launch server";
public static final String DSP_MODE_CONNECT = "connect to server";
/** String */
public static final String ATTR_DSP_CMD = ID_DSP_DEBUG_MODEL + ".ATTR_DSP_CMD";
/** List<String> */
public static final String ATTR_DSP_ARGS = ID_DSP_DEBUG_MODEL + ".ATTR_DSP_ARGS";
/** String - should be properly formed JSON */
public static final String ATTR_DSP_PARAM = ID_DSP_DEBUG_MODEL + ".ATTR_DSP_PARAM";
/** String */
public static final String ATTR_DSP_SERVER_HOST = ID_DSP_DEBUG_MODEL + ".ATTR_DSP_SERVER_HOST";
/** Integer */
public static final String ATTR_DSP_SERVER_PORT = ID_DSP_DEBUG_MODEL + ".ATTR_DSP_SERVER_PORT";
/** Boolean */
public static final String ATTR_DSP_MONITOR_DEBUG_ADAPTER = ID_DSP_DEBUG_MODEL + ".ATTR_DSP_MONITOR_ADAPTER";
/** Boolean */
public static final String ATTR_CUSTOM_DEBUG_ADAPTER = ID_DSP_DEBUG_MODEL + ".ATTR_CUSTOM_DEBUG_ADAPTER";
/** Boolean */
public static final String ATTR_CUSTOM_LAUNCH_PARAMS = ID_DSP_DEBUG_MODEL + ".ATTR_CUSTOM_LAUNCH_PARAMS";
// The shared instance
private static volatile @Nullable DSPPlugin plugin;
public DSPPlugin() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static DSPPlugin getDefault() {
Assert.isNotNull(plugin);
return plugin;
}
/**
* Utility method to log errors.
*
* @param thr The exception through which we noticed the error
*/
public static void logError(final Throwable thr) {
logError(thr.getMessage(), thr);
}
/**
* Utility method to log errors.
*
* @param message User comprehensible message
* @param thr The exception through which we noticed the error
*/
public static void logError(final @Nullable String message, final @Nullable Throwable thr) {
log(IStatus.ERROR, message, thr);
}
/**
* Log an info message for this plug-in
*
* @param message
*/
public static void logInfo(final String message) {
log(IStatus.INFO, message, null);
}
/**
* Utility method to log warnings for this plug-in.
*
* @param message User comprehensible message
* @param thr The exception through which we noticed the warning
*/
public static void logWarning(final String message, final @Nullable Throwable thr) {
log(IStatus.WARNING, message, thr);
}
private static void log(final int severity, @Nullable String message, final @Nullable Throwable thr) {
ResponseError error = null;
if (thr instanceof ResponseErrorException responseErrorException) {
error = responseErrorException.getResponseError();
} else if (thr != null && thr.getCause() instanceof ResponseErrorException responseErrorException) {
error = responseErrorException.getResponseError();
}
if (error != null) {
try {
message += " - response error: " + error.toString();
} catch (Exception e) {
message += " - response error formatting exception " + e.getMessage();
}
}
getDefault().getLog().log(new Status(severity, PLUGIN_ID, 0, message, thr));
}
@Override
protected void initializeImageRegistry(ImageRegistry registry) {
DSPImages.initialize(registry);
}
}