@@ -38,6 +38,7 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams)
38
38
svc .server = jrpc2 .ServerFromContext (ctx )
39
39
40
40
setupTelemetry (expClientCaps , svc , ctx , properties )
41
+ defer svc .telemetry .SendEvent (ctx , "initialize" , properties )
41
42
42
43
if params .ClientInfo .Name != "" {
43
44
err = ilsp .SetClientName (ctx , params .ClientInfo .Name )
@@ -126,9 +127,11 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams)
126
127
})
127
128
}
128
129
} else {
129
- if ! uri .IsURIValid (string (params .RootURI )) {
130
+ rootURI := string (params .RootURI )
131
+ if ! uri .IsURIValid (rootURI ) {
130
132
properties ["root_uri" ] = "invalid"
131
- return serverCaps , fmt .Errorf ("URI %q is not valid" , params .RootURI )
133
+ return serverCaps , fmt .Errorf ("Unsupported or invalid URI: %q " +
134
+ "This is most likely bug, please report it." , rootURI )
132
135
}
133
136
134
137
err := svc .setupWalker (ctx , params , cfgOpts )
@@ -162,7 +165,6 @@ func setupTelemetry(expClientCaps lsp.ExpClientCapabilities, svc *service, ctx c
162
165
}
163
166
svc .logger .Printf ("telemetry enabled (version: %d)" , tv )
164
167
}
165
- defer svc .telemetry .SendEvent (ctx , "initialize" , properties )
166
168
}
167
169
168
170
func getTelemetryProperties (out * settings.DecodedOptions ) map [string ]interface {} {
@@ -238,7 +240,8 @@ func initializeResult(ctx context.Context) lsp.InitializeResult {
238
240
}
239
241
240
242
func (svc * service ) setupWalker (ctx context.Context , params lsp.InitializeParams , options * settings.Options ) error {
241
- root := document .DirHandleFromURI (string (params .RootURI ))
243
+ rootURI := string (params .RootURI )
244
+ root := document .DirHandleFromURI (rootURI )
242
245
243
246
err := lsctx .SetRootDirectory (ctx , root .Path ())
244
247
if err != nil {
@@ -261,15 +264,24 @@ func (svc *service) setupWalker(ctx context.Context, params lsp.InitializeParams
261
264
}
262
265
263
266
if len (params .WorkspaceFolders ) > 0 {
264
- for _ , folderPath := range params .WorkspaceFolders {
265
- modPath := document .DirHandleFromURI (folderPath .URI )
267
+ for _ , folder := range params .WorkspaceFolders {
268
+ if ! uri .IsURIValid (folder .URI ) {
269
+ jrpc2 .ServerFromContext (ctx ).Notify (ctx , "window/showMessage" , & lsp.ShowMessageParams {
270
+ Type : lsp .Warning ,
271
+ Message : fmt .Sprintf ("Ignoring workspace folder (unsupport or invalid URI) %s." +
272
+ " This is most likely bug, please report it." , folder .URI ),
273
+ })
274
+ continue
275
+ }
276
+
277
+ modPath := document .DirHandleFromURI (folder .URI )
266
278
267
279
err := svc .stateStore .WalkerPaths .EnqueueDir (modPath )
268
280
if err != nil {
269
281
jrpc2 .ServerFromContext (ctx ).Notify (ctx , "window/showMessage" , & lsp.ShowMessageParams {
270
282
Type : lsp .Warning ,
271
283
Message : fmt .Sprintf ("Ignoring workspace folder %s: %s." +
272
- " This is most likely bug, please report it." , folderPath .URI , err ),
284
+ " This is most likely bug, please report it." , folder .URI , err ),
273
285
})
274
286
continue
275
287
}
0 commit comments