14
14
limitations under the License.
15
15
*/
16
16
import { StreamInfo } from "vscode-languageclient/node" ;
17
- import { getUserConfigLaunchOptionsDefaults , prepareNbcodeLaunchOptions } from "./launchOptions" ;
17
+ import { getUserConfigLaunchOptionsDefaults } from "./launchOptions" ;
18
18
import { globalVars , LOGGER } from "../extension" ;
19
19
import { configKeys } from "../configurations/configuration" ;
20
- import { NbProcessManager } from "./nbProcessManager" ;
21
- import { enableDisableModules , findNbcode } from "./utils" ;
20
+ import { enableDisableModules } from "./utils" ;
22
21
import * as net from 'net' ;
23
- import { extConstants , NODE_WINDOWS_LABEL } from "../constants" ;
24
- import { l10n } from "../localiser" ;
25
- import { window } from "vscode" ;
26
22
import { ChildProcess } from "child_process" ;
27
- import { jdkDownloaderPrompt } from "../webviews/jdkDownloader/prompt" ;
28
- import * as os from 'os' ;
29
- import { LogLevel } from "../logger" ;
30
- import { isNbJavacDisabledHandler } from "../configurations/handlers" ;
31
-
32
- const launchNbcode = ( ) : void => {
33
- const ideLaunchOptions = prepareNbcodeLaunchOptions ( ) ;
34
- const userdir = getUserConfigLaunchOptionsDefaults ( ) [ configKeys . userdir ] . value ;
35
- const specifiedJDK = getUserConfigLaunchOptionsDefaults ( ) [ configKeys . jdkHome ] . value ;
36
- const extensionPath = globalVars . extensionInfo . getExtensionStorageUri ( ) . fsPath ;
37
- const nbcodePath = findNbcode ( extensionPath ) ;
38
-
39
- const requiredJdk = specifiedJDK ? specifiedJDK : 'default system JDK' ;
40
- let launchMsg = l10n . value ( "jdk.extension.lspServer.statusBar.message.launching" , {
41
- SERVER_NAME : extConstants . SERVER_NAME ,
42
- requiredJdk : requiredJdk ,
43
- userdir : userdir
44
- } ) ;
45
- LOGGER . log ( launchMsg ) ;
46
- window . setStatusBarMessage ( launchMsg , 2000 ) ;
47
-
48
- globalVars . nbProcessManager = new NbProcessManager ( userdir , nbcodePath , ideLaunchOptions ) ;
49
- globalVars . nbProcessManager . startProcess ( ) ;
50
- }
23
+ import { getConfigurationValue , isNbJavacDisabledHandler } from "../configurations/handlers" ;
24
+ import { attachNbProcessListeners , launchNbcode } from "./nbcode" ;
25
+ import { NbLanguageClient } from "./nbLanguageClient" ;
26
+ import { NbTestAdapter } from "../testAdapter" ;
27
+ import { registerListenersAfterClientInit } from "../listener" ;
28
+ import { registerNotificationListeners } from "./notifications/register" ;
29
+ import { registerRequestListeners } from "./requests/register" ;
30
+ import { TreeViewService , Visualizer } from "../explorer" ;
31
+ import { commands , TextEditor , TreeView , window , workspace } from "vscode" ;
32
+ import { extConstants } from "../constants" ;
33
+ import { extCommands } from "../commands/commands" ;
51
34
52
35
const establishConnection = ( ) => new Promise < StreamInfo > ( ( resolve , reject ) => {
53
36
const nbProcess = globalVars . nbProcessManager ?. getProcess ( ) ;
@@ -61,21 +44,8 @@ const establishConnection = () => new Promise<StreamInfo>((resolve, reject) => {
61
44
LOGGER . log ( `LSP server launching: ${ nbProcessManager . getProcessId ( ) } ` ) ;
62
45
LOGGER . log ( `LSP server user directory: ${ getUserConfigLaunchOptionsDefaults ( ) [ configKeys . userdir ] . value } ` ) ;
63
46
64
- let status = false ;
65
- nbProcess . stdout ?. on ( 'data' , ( d : any ) => {
66
- status = processOnDataHandler ( nbProcessManager , d . toString ( ) , true ) ;
67
- } ) ;
68
- nbProcess . stderr ?. on ( 'data' , ( d : any ) => {
69
- processOnDataHandler ( nbProcessManager , d . toString ( ) , false ) ;
70
- } ) ;
71
- nbProcess . on ( 'close' , ( code : number ) => {
72
- const status = processOnCloseHandler ( nbProcessManager , code )
73
- if ( status != null ) {
74
- reject ( status ) ;
75
- }
76
- } ) ;
77
-
78
47
try {
48
+ attachNbProcessListeners ( nbProcessManager ) ;
79
49
connectToServer ( nbProcess ) . then ( server => resolve ( {
80
50
reader : server ,
81
51
writer : server
@@ -121,55 +91,11 @@ const connectToServer = (nbProcess: ChildProcess): Promise<net.Socket> => {
121
91
} ) ;
122
92
}
123
93
124
- const processOnDataHandler = ( nbProcessManager : NbProcessManager , text : string , isOut : boolean ) => {
125
- if ( nbProcessManager ) {
126
- globalVars . clientPromise . activationPending = false ;
127
- }
128
- LOGGER . logNoNL ( text ) ;
129
- isOut ? nbProcessManager . appendStdOut ( text ) : nbProcessManager . appendStdErr ( text ) ;
130
-
131
- if ( nbProcessManager . getStdOut ( ) ?. match ( / o r g .n e t b e a n s .m o d u l e s .j a v a .l s p .s e r v e r / ) ) {
132
- return true ;
133
- }
134
- return false ;
135
- }
136
-
137
-
138
- const processOnCloseHandler = ( nbProcessManager : NbProcessManager , code : number ) : string | null => {
139
- const globalnbProcessManager = globalVars . nbProcessManager ;
140
- if ( globalnbProcessManager == nbProcessManager ) {
141
- globalVars . nbProcessManager = null ;
142
- if ( code != 0 ) {
143
- window . showWarningMessage ( l10n . value ( "jdk.extension.lspServer.warning_message.serverExited" , { SERVER_NAME : extConstants . SERVER_NAME , code : code } ) ) ;
144
- }
145
- }
146
- if ( nbProcessManager . getStdOut ( ) ?. match ( / C a n n o t f i n d j a v a / ) || ( os . type ( ) === NODE_WINDOWS_LABEL && ! globalVars . deactivated ) ) {
147
- jdkDownloaderPrompt ( ) ;
148
- }
149
- if ( nbProcessManager . getStdOut ( ) != null ) {
150
- let match = nbProcessManager . getStdOut ( ) ! . match ( / o r g .n e t b e a n s .m o d u l e s .j a v a .l s p .s e r v e r [ ^ \n ] * / )
151
- if ( match ?. length == 1 ) {
152
- LOGGER . log ( match [ 0 ] ) ;
153
- } else {
154
- LOGGER . log ( "Cannot find org.netbeans.modules.java.lsp.server in the log!" , LogLevel . ERROR ) ;
155
- }
156
- LOGGER . log ( `Please refer to troubleshooting section for more info: https://github.com/oracle/javavscode/blob/main/README.md#troubleshooting` ) ;
157
- LOGGER . showOutputChannelUI ( false ) ;
158
-
159
- nbProcessManager . killProcess ( false ) ;
160
- return l10n . value ( "jdk.extension.error_msg.notEnabled" , { SERVER_NAME : extConstants . SERVER_NAME } ) ;
161
- } else {
162
- LOGGER . log ( `LSP server ${ nbProcessManager . getProcessId ( ) } terminated with ${ code } ` ) ;
163
- LOGGER . log ( `Exit code ${ code } ` ) ;
164
- }
165
- return null ;
166
- }
167
-
168
94
const enableDisableNbjavacModule = ( ) => {
169
95
const userdirPath = getUserConfigLaunchOptionsDefaults ( ) [ configKeys . userdir ] . value
170
96
const nbjavacValue = isNbJavacDisabledHandler ( ) ;
171
97
const extensionPath = globalVars . extensionInfo . getExtensionStorageUri ( ) . fsPath ;
172
- enableDisableModules ( extensionPath , userdirPath , [ 'org.netbeans.libs.nbjavacapi' ] , nbjavacValue ) ;
98
+ enableDisableModules ( extensionPath , userdirPath , [ 'org.netbeans.libs.nbjavacapi' ] , ! nbjavacValue ) ;
173
99
}
174
100
175
101
const serverBuilder = ( ) => {
@@ -179,7 +105,7 @@ const serverBuilder = () => {
179
105
}
180
106
181
107
export const clientInit = ( ) => {
182
- const connection : ( ) => Promise < StreamInfo > = serverBuilder ( ) ;
108
+ const connection : ( ) => Promise < StreamInfo > = serverOptionsBuilder ( ) ;
183
109
const client = NbLanguageClient . build ( connection , LOGGER ) ;
184
110
185
111
LOGGER . log ( 'Language Client: Starting' ) ;
0 commit comments