MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / createClient

Method createClient

src/extension/analysis/analyzer.ts:392–512  ·  view source on GitHub ↗
(logger: Logger, sdks: DartSdks, dartCapabilities: DartCapabilities, wsContext: WorkspaceContext, middleware: ls.Middleware)

Source from the content-addressed store, hash-verified

390 }
391
392 private createClient(logger: Logger, sdks: DartSdks, dartCapabilities: DartCapabilities, wsContext: WorkspaceContext, middleware: ls.Middleware): LanguageClient {
393 const converters = new LspUriConverters(!!config.normalizeFileCasing);
394 const clientOptions: ls.LanguageClientOptions = {
395 errorHandler: new DartErrorHandler(logger),
396 initializationFailedHandler: (error: ls.ResponseError<ls.InitializeError> | Error | any) => {
397 logger.warn(`Failed to initialize LSP server: ${error}`);
398 return false; // Let client handle reinitialization.
399 },
400 initializationOptions: {
401 allowOpenUri: true,
402 appHost: vs.env.appHost,
403 closingLabels: config.closingLabels,
404 completionBudgetMilliseconds: config.completionBudgetMilliseconds,
405 // Flutter Outline notifications/data are used for Flutter UI Guides and
406 // icon previews, so we still need this even though the outline itself
407 // has been removed.
408 flutterOutline: wsContext.hasAnyFlutterProjects,
409 hostKind,
410 onlyAnalyzeProjectsWithOpenFiles: config.onlyAnalyzeProjectsWithOpenFiles,
411 outline: true,
412 // For legacy SDKs, removed from server in https://dart-review.googlesource.com/c/sdk/+/349742
413 // Can be removed in future when the SDKs that needed the flag is a small enough portion that
414 // it's ok for them to not get the surveys.
415 previewSurveys: true,
416 remoteName: vs.env.remoteName,
417 suggestFromUnimportedLibraries: config.autoImportCompletions,
418 useInEditorDartFixPrompt: true,
419 },
420 markdown: {
421 supportHtml: true,
422 },
423 middleware,
424 outputChannelName: "LSP",
425 revealOutputChannelOn: ls.RevealOutputChannelOn.Never,
426 textSynchronization: {
427 // Prevent sending didOpen/didClose events for "fake" opens, like
428 // when holding Ctrl and hovering a symbol that shows a preview.
429 // VS Code fires open/close events whenever it opens the model for
430 // reading, not only when the user opens the file. The server only
431 // cares about the latter.
432 // TODO(dantup): Consider putting this back once we've diagnosed
433 // https://github.com/Dart-Code/Dart-Code/issues/6088
434 // delayOpenNotifications: true,
435 },
436 uriConverters: {
437 // Don't just use "converters" here because LSP doesn't bind "this".
438 code2Protocol: (uri) => converters.code2Protocol(uri),
439 protocol2Code: (file) => converters.protocol2Code(file),
440 },
441 };
442
443 const client = new LanguageClient(
444 "dartAnalysisLSP",
445 "Dart Analysis Server",
446 async () => {
447 try {
448 const streamInfo = await this.spawnServer(logger, sdks);
449 const jsonEncoder = ls.RAL().applicationJson.encoder;

Callers 1

constructorMethod · 0.95

Calls 4

code2ProtocolMethod · 0.95
protocol2CodeMethod · 0.95
spawnServerMethod · 0.95
warnMethod · 0.65

Tested by

no test coverage detected