Skip to content

Commit 6741db2

Browse files
committed
Fix
Task #92 - Incorrect examples in the default LSP Server configuration.
1 parent 29938c8 commit 6741db2

10 files changed

Lines changed: 1134 additions & 210 deletions

File tree

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@
266266
</plugins>
267267
</build>
268268
<dependencies>
269+
<dependency>
270+
<groupId>com.networknt</groupId>
271+
<artifactId>json-schema-validator</artifactId>
272+
<version>1.0.87</version>
273+
</dependency>
269274
<dependency>
270275
<groupId>io.vavr</groupId>
271276
<artifactId>vavr</artifactId>

src/main/java/org/netbeans/modules/python/PythonUtility.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public class PythonUtility {
127127
};
128128

129129
public static final File SETTINGS = PythonUtility.PYLSP_VENV_DIR.toPath().resolve("settings.json").toFile();
130+
public static final File SETTINGS_SCHEMA = PythonUtility.PYLSP_VENV_DIR.toPath().resolve("schema.json").toFile();
130131
public static final File REPOS = PythonUtility.PYLSP_VENV_DIR.toPath().resolve("repos.json").toFile();
131132
public static final File PLATFORMS = PythonUtility.PYLSP_VENV_DIR.toPath().resolve("platforms.json").toFile();
132133
public static final File ENVS = PythonUtility.PYLSP_VENV_DIR.toPath().resolve("envs.json").toFile();
@@ -385,6 +386,10 @@ public static int installLsp(ClassLoader cl) {
385386
IOUtils.resourceToString("org/netbeans/modules/python/settings.json",
386387
StandardCharsets.UTF_8, cl)
387388
);
389+
Files.writeString(SETTINGS_SCHEMA.toPath(),
390+
IOUtils.resourceToString("org/netbeans/modules/python/schema.json",
391+
StandardCharsets.UTF_8, cl)
392+
);
388393
Files.writeString(REPOS.toPath(),
389394
IOUtils.resourceToString("org/netbeans/modules/python/repos.json",
390395
StandardCharsets.UTF_8, cl)
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Copy from /netbeans/platform/o.n.core/src/org/netbeans/core/actions/LogAction.java
3+
*/
4+
package org.netbeans.modules.python.log;
5+
6+
import java.io.*;
7+
import java.util.*;
8+
import java.util.logging.Level;
9+
import java.util.logging.Logger;
10+
import org.openide.util.*;
11+
import org.openide.windows.*;
12+
13+
/**
14+
* Connects the output stream of a file to the IDE output window.
15+
*
16+
*/
17+
public class LogViewerSupport implements Runnable {
18+
19+
private static final RequestProcessor RP = new RequestProcessor(LogViewerSupport.class);
20+
boolean shouldStop = false;
21+
FileInputStream filestream = null;
22+
BufferedReader ins;
23+
InputOutput io;
24+
File fileName;
25+
String ioName;
26+
int lines;
27+
Ring ring;
28+
private final RequestProcessor.Task task = RP.create(this);
29+
30+
/**
31+
* Connects a given process to the output window. Returns immediately, but
32+
* threads are started that copy streams of the process to/from the output
33+
* window.
34+
*
35+
* @param fileName process whose streams to connect to the output window
36+
* @param ioName name of the output window tab to use
37+
*/
38+
public LogViewerSupport(final File fileName, final String ioName) {
39+
40+
this.fileName = fileName;
41+
this.ioName = ioName;
42+
}
43+
44+
private void init() {
45+
final int LINES = 2000;
46+
final int OLD_LINES = 2000;
47+
ring = new Ring(OLD_LINES);
48+
String line;
49+
50+
// Read the log file without
51+
// displaying everything
52+
try {
53+
while ((line = ins.readLine()) != null) {
54+
ring.add(line);
55+
} // end of while ((line = ins.readLine()) != null)
56+
} catch (IOException e) {
57+
Logger.getLogger(LogViewerSupport.class.getName()).log(Level.INFO, null, e);
58+
} // end of try-catch
59+
60+
// Now show the last OLD_LINES
61+
lines = ring.output();
62+
ring.setMaxCount(LINES);
63+
}
64+
65+
public void run() {
66+
final int MAX_LINES = 10000;
67+
String line;
68+
69+
shouldStop = io.isClosed();
70+
71+
if (!shouldStop) {
72+
try {
73+
if (lines >= MAX_LINES) {
74+
io.getOut().reset();
75+
lines = ring.output();
76+
} // end of if (lines >= MAX_LINES)
77+
78+
while ((line = ins.readLine()) != null) {
79+
if ((line = ring.add(line)) != null) {
80+
io.getOut().println(line);
81+
lines++;
82+
} // end of if ((line = ring.add(line)) != null)
83+
}
84+
85+
} catch (IOException e) {
86+
Logger.getLogger(LogViewerSupport.class.getName()).log(Level.INFO, null, e);
87+
}
88+
task.schedule(10000);
89+
} else {
90+
///System.out.println("end of infinite loop for log viewer\n\n\n\n");
91+
stopUpdatingLogViewer();
92+
}
93+
}
94+
95+
/* display the log viewer dialog
96+
*
97+
**/
98+
public void showLogViewer() throws IOException {
99+
shouldStop = false;
100+
io = IOProvider.getDefault().getIO(ioName, false);
101+
io.getOut().reset();
102+
io.select();
103+
filestream = new FileInputStream(fileName);
104+
ins = new BufferedReader(new InputStreamReader(filestream));
105+
RP.post(new Runnable() {
106+
@Override
107+
public void run() {
108+
init();
109+
task.schedule(0);
110+
}
111+
});
112+
}
113+
114+
/* stop to update the log viewer dialog
115+
*
116+
**/
117+
public void stopUpdatingLogViewer() {
118+
try {
119+
ins.close();
120+
filestream.close();
121+
io.closeInputOutput();
122+
io.setOutputVisible(false);
123+
} catch (IOException e) {
124+
Logger.getLogger(LogViewerSupport.class.getName()).log(Level.INFO, null, e);
125+
}
126+
}
127+
128+
private class Ring {
129+
130+
private int maxCount;
131+
private int count;
132+
private LinkedList<String> anchor;
133+
134+
public Ring(int max) {
135+
maxCount = max;
136+
count = 0;
137+
anchor = new LinkedList<String>();
138+
}
139+
140+
public String add(String line) {
141+
if (line == null || line.equals("")) { // NOI18N
142+
return null;
143+
} // end of if (line == null || line.equals(""))
144+
145+
while (count >= maxCount) {
146+
anchor.removeFirst();
147+
count--;
148+
} // end of while (count >= maxCount)
149+
150+
anchor.addLast(line);
151+
count++;
152+
153+
return line;
154+
}
155+
156+
public void setMaxCount(int newMax) {
157+
maxCount = newMax;
158+
}
159+
160+
public int output() {
161+
int i = 0;
162+
for (String s : anchor) {
163+
io.getOut().println(s);
164+
i++;
165+
}
166+
167+
return i;
168+
}
169+
170+
public void reset() {
171+
anchor = new LinkedList<String>();
172+
}
173+
}
174+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.netbeans.modules.python.log;
2+
3+
import java.awt.event.ActionEvent;
4+
import java.awt.event.ActionListener;
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.util.logging.Level;
8+
import java.util.logging.Logger;
9+
import org.netbeans.modules.python.PythonUtility;
10+
import org.openide.awt.ActionID;
11+
import org.openide.awt.ActionReference;
12+
import org.openide.awt.ActionRegistration;
13+
import org.openide.util.NbBundle.Messages;
14+
15+
@ActionID(
16+
category = "File",
17+
id = "org.netbeans.modules.python.log.PythonLspLog"
18+
)
19+
@ActionRegistration(
20+
displayName = "#CTL_PythonLspLog"
21+
)
22+
@ActionReference(path = "Menu/View", position = 550)
23+
@Messages("CTL_PythonLspLog=Python Lsp Log")
24+
public final class PythonLspLog implements ActionListener {
25+
26+
@Override
27+
public void actionPerformed(ActionEvent e) {
28+
29+
File f = PythonUtility.PYLSP_VENV_DIR.toPath().resolve("lsp_log_file").toFile();
30+
31+
if (!f.exists()) {
32+
return;
33+
}
34+
35+
LogViewerSupport p = new LogViewerSupport(f, Bundle.CTL_PythonLspLog());
36+
try {
37+
p.showLogViewer();
38+
} catch (IOException ex) {
39+
Logger.getLogger(PythonLspLog.class.getName()).log(Level.INFO, "Showing Python Lsp log action failed", ex);
40+
}
41+
}
42+
}

src/main/java/org/netbeans/modules/python/options/PythonLspServerConfigsPanel.form

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@
9494
<EmptySpace min="-2" max="-2" attributes="0"/>
9595
<Component id="lspServerCheckBox" min="-2" max="-2" attributes="0"/>
9696
<EmptySpace min="-2" pref="56" max="-2" attributes="0"/>
97-
<Component id="lspScrollPane" pref="333" max="32767" attributes="0"/>
98-
<EmptySpace min="-2" max="-2" attributes="0"/>
97+
<Component id="lspScrollPane" pref="309" max="32767" attributes="0"/>
98+
<EmptySpace min="-2" pref="30" max="-2" attributes="0"/>
9999
</Group>
100100
</Group>
101101
</Group>
@@ -166,9 +166,13 @@
166166
<Layout>
167167
<DimensionLayout dim="0">
168168
<Group type="103" groupAlignment="0" attributes="0">
169-
<EmptySpace min="0" pref="369" max="32767" attributes="0"/>
169+
<Group type="102" alignment="0" attributes="0">
170+
<EmptySpace max="-2" attributes="0"/>
171+
<Component id="errroLabel" pref="357" max="32767" attributes="0"/>
172+
<EmptySpace max="-2" attributes="0"/>
173+
</Group>
170174
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
171-
<Group type="102" attributes="0">
175+
<Group type="102" alignment="0" attributes="0">
172176
<EmptySpace max="-2" attributes="0"/>
173177
<Component id="lspSettingsScrollPane" pref="357" max="32767" attributes="0"/>
174178
<EmptySpace max="-2" attributes="0"/>
@@ -178,12 +182,16 @@
178182
</DimensionLayout>
179183
<DimensionLayout dim="1">
180184
<Group type="103" groupAlignment="0" attributes="0">
181-
<EmptySpace min="0" pref="424" max="32767" attributes="0"/>
185+
<Group type="102" alignment="1" attributes="0">
186+
<EmptySpace pref="418" max="32767" attributes="0"/>
187+
<Component id="errroLabel" min="-2" max="-2" attributes="0"/>
188+
<EmptySpace max="-2" attributes="0"/>
189+
</Group>
182190
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
183-
<Group type="102" attributes="0">
184-
<EmptySpace min="-2" max="-2" attributes="0"/>
185-
<Component id="lspSettingsScrollPane" pref="412" max="32767" attributes="0"/>
191+
<Group type="102" alignment="0" attributes="0">
186192
<EmptySpace min="-2" max="-2" attributes="0"/>
193+
<Component id="lspSettingsScrollPane" pref="390" max="32767" attributes="0"/>
194+
<EmptySpace min="-2" pref="28" max="-2" attributes="0"/>
187195
</Group>
188196
</Group>
189197
</Group>
@@ -222,6 +230,16 @@
222230
</Component>
223231
</SubComponents>
224232
</Container>
233+
<Component class="javax.swing.JLabel" name="errroLabel">
234+
<Properties>
235+
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
236+
<Color blue="0" green="0" red="ff" type="rgb"/>
237+
</Property>
238+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
239+
<ResourceString bundle="org/netbeans/modules/python/options/Bundle.properties" key="PythonLspServerConfigsPanel.errroLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
240+
</Property>
241+
</Properties>
242+
</Component>
225243
</SubComponents>
226244
</Container>
227245
</SubComponents>

0 commit comments

Comments
 (0)