1414 limitations under the License.
1515*/
1616import { StreamInfo } from "vscode-languageclient/node" ;
17- import { getUserConfigLaunchOptionsDefaults , prepareNbcodeLaunchOptions } from "./launchOptions" ;
17+ import { getUserConfigLaunchOptionsDefaults } from "./launchOptions" ;
1818import { globalVars , LOGGER } from "../extension" ;
1919import { configKeys } from "../configurations/configuration" ;
20- import { NbProcessManager } from "./nbProcessManager" ;
21- import { enableDisableModules , findNbcode } from "./utils" ;
20+ import { enableDisableModules } from "./utils" ;
2221import * as net from 'net' ;
23- import { extConstants , NODE_WINDOWS_LABEL } from "../constants" ;
24- import { l10n } from "../localiser" ;
25- import { window } from "vscode" ;
2622import { 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" ;
5134
5235const establishConnection = ( ) => new Promise < StreamInfo > ( ( resolve , reject ) => {
5336 const nbProcess = globalVars . nbProcessManager ?. getProcess ( ) ;
@@ -61,21 +44,8 @@ const establishConnection = () => new Promise<StreamInfo>((resolve, reject) => {
6144 LOGGER . log ( `LSP server launching: ${ nbProcessManager . getProcessId ( ) } ` ) ;
6245 LOGGER . log ( `LSP server user directory: ${ getUserConfigLaunchOptionsDefaults ( ) [ configKeys . userdir ] . value } ` ) ;
6346
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-
7847 try {
48+ attachNbProcessListeners ( nbProcessManager ) ;
7949 connectToServer ( nbProcess ) . then ( server => resolve ( {
8050 reader : server ,
8151 writer : server
@@ -121,55 +91,11 @@ const connectToServer = (nbProcess: ChildProcess): Promise<net.Socket> => {
12191 } ) ;
12292}
12393
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-
16894const enableDisableNbjavacModule = ( ) => {
16995 const userdirPath = getUserConfigLaunchOptionsDefaults ( ) [ configKeys . userdir ] . value
17096 const nbjavacValue = isNbJavacDisabledHandler ( ) ;
17197 const extensionPath = globalVars . extensionInfo . getExtensionStorageUri ( ) . fsPath ;
172- enableDisableModules ( extensionPath , userdirPath , [ 'org.netbeans.libs.nbjavacapi' ] , nbjavacValue ) ;
98+ enableDisableModules ( extensionPath , userdirPath , [ 'org.netbeans.libs.nbjavacapi' ] , ! nbjavacValue ) ;
17399}
174100
175101const serverBuilder = ( ) => {
@@ -179,7 +105,7 @@ const serverBuilder = () => {
179105}
180106
181107export const clientInit = ( ) => {
182- const connection : ( ) => Promise < StreamInfo > = serverBuilder ( ) ;
108+ const connection : ( ) => Promise < StreamInfo > = serverOptionsBuilder ( ) ;
183109 const client = NbLanguageClient . build ( connection , LOGGER ) ;
184110
185111 LOGGER . log ( 'Language Client: Starting' ) ;
0 commit comments