@@ -27,7 +27,7 @@ let shutdownRequestAlreadyReceived = false;
2727let stupidFileContentCache : { [ key : string ] : string } = {
2828}
2929
30- let findDirOfFileNearFile = ( fileToFind : p . DocumentUri , source : p . DocumentUri ) => {
30+ let findDirOfFileNearFile = ( fileToFind : p . DocumentUri , source : p . DocumentUri ) : null | p . DocumentUri => {
3131 let dir = path . dirname ( source )
3232 if ( fs . existsSync ( path . join ( dir , fileToFind ) ) ) {
3333 return dir
@@ -36,7 +36,7 @@ let findDirOfFileNearFile = (fileToFind: p.DocumentUri, source: p.DocumentUri) =
3636 // reached top
3737 return null
3838 } else {
39- findDirOfFileNearFile ( fileToFind , dir )
39+ return findDirOfFileNearFile ( fileToFind , dir )
4040 }
4141 }
4242}
@@ -70,9 +70,10 @@ let formatUsingValidBscPath = (code: string, bscPath: p.DocumentUri, isInterface
7070 }
7171}
7272
73- // let startWatchingBsbOutputFile = () => {
74- // fs.watch()
75- // }
73+ let startWatchingBsbOutputFile = ( root : p . DocumentUri ) => {
74+ console . log ( root )
75+ // fs.watch()
76+ }
7677// let stopWatchingBsbOutputFile = () => {
7778// fs.unwatchFile()
7879// }
@@ -83,6 +84,8 @@ process.on('message', (a: (m.RequestMessage | m.NotificationMessage)) => {
8384 let aa = ( a as m . NotificationMessage )
8485 if ( ! initialized && aa . method !== 'exit' ) {
8586 // From spec: "Notifications should be dropped, except for the exit notification. This will allow the exit of a server without an initialize request"
87+ // For us: do nothing. We don't have anything we need to clean up right now
88+ // TODO: think of fs watcher
8689 } else if ( aa . method === 'exit' ) {
8790 // The server should exit with success code 0 if the shutdown request has been received before; otherwise with error code 1
8891 if ( shutdownRequestAlreadyReceived ) {
@@ -120,8 +123,15 @@ process.on('message', (a: (m.RequestMessage | m.NotificationMessage)) => {
120123 } ;
121124 ( < any > process ) . send ( response ) ;
122125 } else if ( aa . method === 'initialize' ) {
126+ let param : p . InitializeParams = aa . params
127+ let root = param . rootUri
128+ if ( root == null ) {
129+ // TODO: handle single file
130+ console . log ( "not handling single file" )
131+ } else {
132+ startWatchingBsbOutputFile ( root )
133+ }
123134 // send the list of things we support
124- // let param: p.InitializeParams = aa.params
125135 let result : p . InitializeResult = {
126136 capabilities : {
127137 // TODO: incremental sync
@@ -137,6 +147,7 @@ process.on('message', (a: (m.RequestMessage | m.NotificationMessage)) => {
137147 initialized = true ;
138148 ( < any > process ) . send ( response ) ;
139149 } else if ( aa . method === 'initialized' ) {
150+ console . log ( 'inited' )
140151 // sent from client after initialize. Nothing to do for now
141152 let response : m . ResponseMessage = {
142153 jsonrpc : jsonrpcVersion ,
@@ -167,6 +178,7 @@ process.on('message', (a: (m.RequestMessage | m.NotificationMessage)) => {
167178 }
168179 } else if ( aa . method === p . DocumentFormattingRequest . method ) {
169180 let params = ( aa . params as p . DocumentFormattingParams )
181+ // TODO: remove this hack
170182 let filePath = params . textDocument . uri . replace ( 'file:' , '' )
171183 let extension = path . extname ( params . textDocument . uri ) ;
172184 if ( extension !== '.res' && extension !== '.resi' ) {
0 commit comments