| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package settings |
| 6 |
|
| 7 |
import ( |
| 8 |
"fmt" |
| 9 |
"maps" |
| 10 |
"math" |
| 11 |
"path/filepath" |
| 12 |
"reflect" |
| 13 |
"strings" |
| 14 |
"time" |
| 15 |
|
| 16 |
"golang.org/x/tools/gopls/internal/file" |
| 17 |
"golang.org/x/tools/gopls/internal/protocol" |
| 18 |
"golang.org/x/tools/gopls/internal/protocol/semtok" |
| 19 |
"golang.org/x/tools/gopls/internal/telemetry" |
| 20 |
"golang.org/x/tools/gopls/internal/util/frob" |
| 21 |
) |
| 22 |
|
| 23 |
|
| 24 |
type Annotation string |
| 25 |
|
| 26 |
const ( |
| 27 |
|
| 28 |
Nil Annotation = "nil" |
| 29 |
|
| 30 |
|
| 31 |
Escape Annotation = "escape" |
| 32 |
|
| 33 |
|
| 34 |
Inline Annotation = "inline" |
| 35 |
|
| 36 |
|
| 37 |
Bounds Annotation = "bounds" |
| 38 |
) |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
type Options struct { |
| 55 |
ClientOptions |
| 56 |
ServerOptions |
| 57 |
UserOptions |
| 58 |
InternalOptions |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
func (o *Options) Debug() []string { |
| 63 |
var res []string |
| 64 |
|
| 65 |
var visitStruct func(v reflect.Value, path []string) |
| 66 |
visitStruct = func(v reflect.Value, path []string) { |
| 67 |
for i := range v.NumField() { |
| 68 |
f := v.Field(i) |
| 69 |
ftyp := v.Type().Field(i) |
| 70 |
path := append(path, ftyp.Name) |
| 71 |
if ftyp.Type.Kind() == reflect.Struct { |
| 72 |
visitStruct(f, path) |
| 73 |
} else { |
| 74 |
res = append(res, fmt.Sprintf("%s = %#v", |
| 75 |
strings.Join(path, "."), |
| 76 |
f.Interface())) |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
visitStruct(reflect.ValueOf(o).Elem(), nil) |
| 81 |
|
| 82 |
return res |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
type ClientOptions struct { |
| 90 |
ClientInfo protocol.ClientInfo |
| 91 |
InsertTextFormat protocol.InsertTextFormat |
| 92 |
InsertReplaceSupported bool |
| 93 |
ConfigurationSupported bool |
| 94 |
DynamicConfigurationSupported bool |
| 95 |
DynamicRegistrationSemanticTokensSupported bool |
| 96 |
DynamicWatchedFilesSupported bool |
| 97 |
RelativePatternsSupported bool |
| 98 |
PreferredContentFormat protocol.MarkupKind |
| 99 |
LineFoldingOnly bool |
| 100 |
HierarchicalDocumentSymbolSupport bool |
| 101 |
ImportsSource ImportsSourceEnum `status:"experimental"` |
| 102 |
SemanticTypes []string |
| 103 |
SemanticMods []string |
| 104 |
RelatedInformationSupported bool |
| 105 |
CompletionTags bool |
| 106 |
CompletionDeprecated bool |
| 107 |
SupportedResourceOperations []protocol.ResourceOperationKind |
| 108 |
CodeActionResolveOptions []string |
| 109 |
ShowDocumentSupported bool |
| 110 |
|
| 111 |
|
| 112 |
SupportedWorkDoneProgressFormats map[WorkDoneProgressStyle]bool |
| 113 |
|
| 114 |
|
| 115 |
SupportedInteractiveInputTypes map[InteractiveInputType]bool |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
type ServerOptions struct { |
| 123 |
SupportedCodeActions map[file.Kind]map[protocol.CodeActionKind]bool |
| 124 |
SupportedCommands []string |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
type BuildOptions struct { |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
BuildFlags []string |
| 133 |
|
| 134 |
|
| 135 |
Env map[string]string |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
DirectoryFilters []string |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
TemplateExtensions []string |
| 161 |
|
| 162 |
|
| 163 |
MemoryMode string `status:"experimental"` |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
ExpandWorkspaceToModule bool `status:"experimental"` |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
StandaloneTags []string |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
WorkspaceFiles []string |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
type UIOptions struct { |
| 206 |
DocumentationOptions |
| 207 |
CompletionOptions |
| 208 |
NavigationOptions |
| 209 |
DiagnosticOptions |
| 210 |
InlayHintOptions |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
Codelenses map[CodeLensSource]bool |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
SemanticTokens bool `status:"experimental"` |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
NoSemanticString bool `status:"experimental"` |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
NoSemanticNumber bool `status:"experimental"` |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
SemanticTokenTypes map[string]bool `status:"experimental"` |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
SemanticTokenModifiers map[string]bool `status:"experimental"` |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
NewGoFileHeader bool |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
RenameMovesSubpackages bool `status:"experimental"` |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
type CodeLensSource string |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
const ( |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
CodeLensGenerate CodeLensSource = "generate" |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
CodeLensRegenerateCgo CodeLensSource = "regenerate_cgo" |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
CodeLensVulncheck CodeLensSource = "vulncheck" |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
CodeLensRunGovulncheck CodeLensSource = "run_govulncheck" |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
CodeLensTest CodeLensSource = "test" |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
CodeLensTidy CodeLensSource = "tidy" |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
CodeLensUpgradeDependency CodeLensSource = "upgrade_dependency" |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
CodeLensVendor CodeLensSource = "vendor" |
| 377 |
) |
| 378 |
|
| 379 |
|
| 380 |
type CompletionOptions struct { |
| 381 |
|
| 382 |
|
| 383 |
UsePlaceholders bool |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
CompletionBudget time.Duration `status:"debug"` |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
Matcher Matcher `status:"advanced"` |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
ExperimentalPostfixCompletions bool `status:"experimental"` |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
CompleteFunctionCalls bool |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
type DocumentationOptions struct { |
| 410 |
|
| 411 |
|
| 412 |
HoverKind HoverKind |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
LinkTarget string |
| 429 |
|
| 430 |
|
| 431 |
LinksInHover LinksInHoverEnum |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
type LinksInHoverEnum int |
| 443 |
|
| 444 |
const ( |
| 445 |
LinksInHover_None LinksInHoverEnum = iota |
| 446 |
LinksInHover_LinkTarget |
| 447 |
LinksInHover_Gopls |
| 448 |
) |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
func (l LinksInHoverEnum) MarshalJSON() ([]byte, error) { |
| 454 |
switch l { |
| 455 |
case LinksInHover_None: |
| 456 |
return []byte("false"), nil |
| 457 |
case LinksInHover_LinkTarget: |
| 458 |
return []byte("true"), nil |
| 459 |
case LinksInHover_Gopls: |
| 460 |
return []byte(`"gopls"`), nil |
| 461 |
default: |
| 462 |
return nil, fmt.Errorf("invalid LinksInHover value %d", l) |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
type FormattingOptions struct { |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
Local string |
| 478 |
|
| 479 |
|
| 480 |
Gofumpt bool |
| 481 |
} |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
type DiagnosticOptions struct { |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
Analyses map[string]bool |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
Staticcheck bool `status:"experimental"` |
| 517 |
StaticcheckProvided bool `status:"experimental"` |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
Annotations map[Annotation]bool |
| 531 |
|
| 532 |
|
| 533 |
Vulncheck VulncheckMode `status:"experimental"` |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
DiagnosticsDelay time.Duration `status:"advanced"` |
| 542 |
|
| 543 |
|
| 544 |
DiagnosticsTrigger DiagnosticsTrigger `status:"experimental"` |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
AnalysisProgressReporting bool |
| 556 |
} |
| 557 |
|
| 558 |
type InlayHintOptions struct { |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
Hints map[InlayHint]bool `status:"experimental"` |
| 563 |
} |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
type InlayHint string |
| 568 |
|
| 569 |
|
| 570 |
const ( |
| 571 |
|
| 572 |
|
| 573 |
» 8) |
| 574 |
|
| 575 |
ParameterNames InlayHint = "parameterNames" |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
r)-1 |
| 580 |
|
| 581 |
AssignVariableTypes InlayHint = "assignVariableTypes" |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
» |
| 587 |
» |
| 588 |
» |
| 589 |
» |
| 590 |
|
| 591 |
|
| 592 |
ConstantValues InlayHint = "constantValues" |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
{} { |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
RangeVariableTypes InlayHint = "rangeVariableTypes" |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
}, |
| 608 |
|
| 609 |
|
| 610 |
CompositeLiteralTypes InlayHint = "compositeLiteralTypes" |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
»2} |
| 615 |
|
| 616 |
0} |
| 617 |
|
| 618 |
CompositeLiteralFieldNames InlayHint = "compositeLiteralFields" |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
") |
| 623 |
|
| 624 |
FunctionTypeParameters InlayHint = "functionTypeParameters" |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
» |
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
IgnoredError InlayHint = "ignoredError" |
| 640 |
) |
| 641 |
|
| 642 |
type NavigationOptions struct { |
| 643 |
|
| 644 |
|
| 645 |
ImportShortcut ImportShortcut |
| 646 |
|
| 647 |
|
| 648 |
SymbolMatcher SymbolMatcher `status:"advanced"` |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
SymbolStyle SymbolStyle `status:"advanced"` |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
SymbolScope SymbolScope |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
type UserOptions struct { |
| 675 |
BuildOptions |
| 676 |
UIOptions |
| 677 |
FormattingOptions |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
FileWatcher FileWatcherMode `status:"experimental"` |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
MaxFileCacheBytes int64 `status:"experimental"` |
| 697 |
|
| 698 |
|
| 699 |
VerboseOutput bool `status:"debug"` |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
func (u *UserOptions) EnvSlice() []string { |
| 704 |
var result []string |
| 705 |
for k, v := range u.Env { |
| 706 |
result = append(result, fmt.Sprintf("%v=%v", k, v)) |
| 707 |
} |
| 708 |
return result |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
func (u *UserOptions) SetEnvSlice(env []string) { |
| 713 |
u.Env = map[string]string{} |
| 714 |
for _, kv := range env { |
| 715 |
split := strings.SplitN(kv, "=", 2) |
| 716 |
if len(split) != 2 { |
| 717 |
continue |
| 718 |
} |
| 719 |
u.Env[split[0]] = split[1] |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
type WorkDoneProgressStyle string |
| 724 |
|
| 725 |
const WorkDoneProgressStyleLog WorkDoneProgressStyle = "log" |
| 726 |
|
| 727 |
type InteractiveInputType string |
| 728 |
|
| 729 |
const ( |
| 730 |
InteractiveInputTypeString InteractiveInputType = "string" |
| 731 |
InteractiveInputTypeFile InteractiveInputType = "file" |
| 732 |
InteractiveInputTypeBool InteractiveInputType = "bool" |
| 733 |
InteractiveInputTypeNumber InteractiveInputType = "number" |
| 734 |
InteractiveInputTypeEnum InteractiveInputType = "enum" |
| 735 |
InteractiveInputTypeLazyEnum InteractiveInputType = "lazyEnum" |
| 736 |
InteractiveInputTypeList InteractiveInputType = "list" |
| 737 |
) |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
type InternalOptions struct { |
| 747 |
|
| 748 |
MCPTools map[string]bool |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
VerboseWorkDoneProgress bool |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
CompletionDocumentation bool |
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
CompleteUnimported bool |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
DeepCompletion bool |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
ShowBugReports bool |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
SubdirWatchPatterns SubdirWatchPatterns |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
ReportAnalysisProgressAfter time.Duration |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
TelemetryPrompt bool |
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
LinkifyShowMessage bool |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
IncludeReplaceInWorkspace bool |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
ZeroConfig bool |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
PullDiagnostics bool |
| 852 |
} |
| 853 |
|
| 854 |
type FileWatcherMode string |
| 855 |
|
| 856 |
const ( |
| 857 |
FileWatcherOff FileWatcherMode = "off" |
| 858 |
FileWatcherFSNotify FileWatcherMode = "fsnotify" |
| 859 |
FileWatcherPoll FileWatcherMode = "poll" |
| 860 |
) |
| 861 |
|
| 862 |
type SubdirWatchPatterns string |
| 863 |
|
| 864 |
const ( |
| 865 |
SubdirWatchPatternsOn SubdirWatchPatterns = "on" |
| 866 |
SubdirWatchPatternsOff SubdirWatchPatterns = "off" |
| 867 |
SubdirWatchPatternsAuto SubdirWatchPatterns = "auto" |
| 868 |
) |
| 869 |
|
| 870 |
type ImportShortcut string |
| 871 |
|
| 872 |
const ( |
| 873 |
BothShortcuts ImportShortcut = "Both" |
| 874 |
LinkShortcut ImportShortcut = "Link" |
| 875 |
DefinitionShortcut ImportShortcut = "Definition" |
| 876 |
) |
| 877 |
|
| 878 |
func (s ImportShortcut) ShowLinks() bool { |
| 879 |
return s == BothShortcuts || s == LinkShortcut |
| 880 |
} |
| 881 |
|
| 882 |
func (s ImportShortcut) ShowDefinition() bool { |
| 883 |
return s == BothShortcuts || s == DefinitionShortcut |
| 884 |
} |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
type ImportsSourceEnum string |
| 892 |
|
| 893 |
const ( |
| 894 |
ImportsSourceOff ImportsSourceEnum = "off" |
| 895 |
ImportsSourceGopls ImportsSourceEnum = "gopls" |
| 896 |
ImportsSourceGoimports ImportsSourceEnum = "goimports" |
| 897 |
) |
| 898 |
|
| 899 |
type Matcher string |
| 900 |
|
| 901 |
const ( |
| 902 |
Fuzzy Matcher = "Fuzzy" |
| 903 |
CaseInsensitive Matcher = "CaseInsensitive" |
| 904 |
CaseSensitive Matcher = "CaseSensitive" |
| 905 |
) |
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
type SymbolMatcher string |
| 910 |
|
| 911 |
const ( |
| 912 |
SymbolFuzzy SymbolMatcher = "Fuzzy" |
| 913 |
SymbolFastFuzzy SymbolMatcher = "FastFuzzy" |
| 914 |
SymbolCaseInsensitive SymbolMatcher = "CaseInsensitive" |
| 915 |
SymbolCaseSensitive SymbolMatcher = "CaseSensitive" |
| 916 |
) |
| 917 |
|
| 918 |
|
| 919 |
type SymbolStyle string |
| 920 |
|
| 921 |
const ( |
| 922 |
|
| 923 |
|
| 924 |
PackageQualifiedSymbols SymbolStyle = "Package" |
| 925 |
|
| 926 |
|
| 927 |
FullyQualifiedSymbols SymbolStyle = "Full" |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
DynamicSymbols SymbolStyle = "Dynamic" |
| 933 |
) |
| 934 |
|
| 935 |
|
| 936 |
type SymbolScope string |
| 937 |
|
| 938 |
const ( |
| 939 |
|
| 940 |
WorkspaceSymbolScope SymbolScope = "workspace" |
| 941 |
|
| 942 |
|
| 943 |
AllSymbolScope SymbolScope = "all" |
| 944 |
) |
| 945 |
|
| 946 |
type HoverKind string |
| 947 |
|
| 948 |
const ( |
| 949 |
SingleLine HoverKind = "SingleLine" |
| 950 |
NoDocumentation HoverKind = "NoDocumentation" |
| 951 |
SynopsisDocumentation HoverKind = "SynopsisDocumentation" |
| 952 |
FullDocumentation HoverKind = "FullDocumentation" |
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
Structured HoverKind = "Structured" |
| 958 |
) |
| 959 |
|
| 960 |
type VulncheckMode string |
| 961 |
|
| 962 |
const ( |
| 963 |
|
| 964 |
ModeVulncheckPrompt VulncheckMode = "Prompt" |
| 965 |
|
| 966 |
ModeVulncheckOff VulncheckMode = "Off" |
| 967 |
|
| 968 |
|
| 969 |
ModeVulncheckImports VulncheckMode = "Imports" |
| 970 |
|
| 971 |
|
| 972 |
) |
| 973 |
|
| 974 |
type DiagnosticsTrigger string |
| 975 |
|
| 976 |
const ( |
| 977 |
|
| 978 |
DiagnosticsOnEdit DiagnosticsTrigger = "Edit" |
| 979 |
|
| 980 |
|
| 981 |
DiagnosticsOnSave DiagnosticsTrigger = "Save" |
| 982 |
|
| 983 |
) |
| 984 |
|
| 985 |
type CounterPath = telemetry.CounterPath |
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
func (o *Options) Set(value any) (applied []CounterPath, errs []error) { |
| 997 |
switch value := value.(type) { |
| 998 |
case nil: |
| 999 |
case map[string]any: |
| 1000 |
seen := make(map[string]struct{}) |
| 1001 |
for name, value := range value { |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
split := strings.Split(name, ".") |
| 1008 |
name = split[len(split)-1] |
| 1009 |
|
| 1010 |
if _, ok := seen[name]; ok { |
| 1011 |
errs = append(errs, fmt.Errorf("duplicate value for %s", name)) |
| 1012 |
} |
| 1013 |
seen[name] = struct{}{} |
| 1014 |
|
| 1015 |
paths, err := o.setOne(name, value) |
| 1016 |
if err != nil { |
| 1017 |
err := fmt.Errorf("setting option %q: %w", name, err) |
| 1018 |
errs = append(errs, err) |
| 1019 |
} |
| 1020 |
_, soft := err.(*SoftError) |
| 1021 |
if err == nil || soft { |
| 1022 |
if len(paths) == 0 { |
| 1023 |
path := CounterPath{name, ""} |
| 1024 |
applied = append(applied, path) |
| 1025 |
} else { |
| 1026 |
for _, subpath := range paths { |
| 1027 |
path := append(CounterPath{name}, subpath...) |
| 1028 |
applied = append(applied, path) |
| 1029 |
} |
| 1030 |
} |
| 1031 |
} |
| 1032 |
} |
| 1033 |
default: |
| 1034 |
errs = append(errs, fmt.Errorf("invalid options type %T (want JSON null or object)", value)) |
| 1035 |
} |
| 1036 |
return applied, errs |
| 1037 |
} |
| 1038 |
|
| 1039 |
func (o *Options) ForClientCapabilities(clientInfo *protocol.ClientInfo, caps protocol.ClientCapabilities) { |
| 1040 |
if clientInfo != nil { |
| 1041 |
o.ClientInfo = *clientInfo |
| 1042 |
} |
| 1043 |
if caps.Workspace.WorkspaceEdit != nil { |
| 1044 |
o.SupportedResourceOperations = caps.Workspace.WorkspaceEdit.ResourceOperations |
| 1045 |
} |
| 1046 |
|
| 1047 |
if c := caps.TextDocument.Completion; c.CompletionItem.SnippetSupport { |
| 1048 |
o.InsertTextFormat = protocol.SnippetTextFormat |
| 1049 |
} |
| 1050 |
o.InsertReplaceSupported = caps.TextDocument.Completion.CompletionItem.InsertReplaceSupport |
| 1051 |
if caps.Window.ShowDocument != nil { |
| 1052 |
o.ShowDocumentSupported = caps.Window.ShowDocument.Support |
| 1053 |
} |
| 1054 |
|
| 1055 |
o.ConfigurationSupported = caps.Workspace.Configuration |
| 1056 |
o.DynamicConfigurationSupported = caps.Workspace.DidChangeConfiguration.DynamicRegistration |
| 1057 |
o.DynamicRegistrationSemanticTokensSupported = caps.TextDocument.SemanticTokens.DynamicRegistration |
| 1058 |
o.DynamicWatchedFilesSupported = caps.Workspace.DidChangeWatchedFiles.DynamicRegistration |
| 1059 |
o.RelativePatternsSupported = caps.Workspace.DidChangeWatchedFiles.RelativePatternSupport |
| 1060 |
|
| 1061 |
|
| 1062 |
if hover := caps.TextDocument.Hover; hover != nil && len(hover.ContentFormat) > 0 { |
| 1063 |
o.PreferredContentFormat = hover.ContentFormat[0] |
| 1064 |
} |
| 1065 |
|
| 1066 |
|
| 1067 |
if fr := caps.TextDocument.FoldingRange; fr != nil { |
| 1068 |
|
| 1069 |
o.LineFoldingOnly = fr.LineFoldingOnly |
| 1070 |
} |
| 1071 |
|
| 1072 |
o.HierarchicalDocumentSymbolSupport = caps.TextDocument.DocumentSymbol.HierarchicalDocumentSymbolSupport |
| 1073 |
|
| 1074 |
|
| 1075 |
o.SemanticTypes = caps.TextDocument.SemanticTokens.TokenTypes |
| 1076 |
o.SemanticMods = caps.TextDocument.SemanticTokens.TokenModifiers |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
o.RelatedInformationSupported = caps.TextDocument.PublishDiagnostics.RelatedInformation |
| 1082 |
|
| 1083 |
if caps.TextDocument.Completion.CompletionItem.TagSupport != nil && |
| 1084 |
caps.TextDocument.Completion.CompletionItem.TagSupport.ValueSet != nil { |
| 1085 |
o.CompletionTags = true |
| 1086 |
} else if caps.TextDocument.Completion.CompletionItem.DeprecatedSupport { |
| 1087 |
o.CompletionDeprecated = true |
| 1088 |
} |
| 1089 |
|
| 1090 |
|
| 1091 |
if caps.TextDocument.CodeAction.DataSupport && caps.TextDocument.CodeAction.ResolveSupport != nil { |
| 1092 |
o.CodeActionResolveOptions = caps.TextDocument.CodeAction.ResolveSupport.Properties |
| 1093 |
} |
| 1094 |
|
| 1095 |
|
| 1096 |
if experimental, ok := caps.Experimental.(map[string]any); ok { |
| 1097 |
if formats, ok := experimental["progressMessageStyles"].([]any); ok { |
| 1098 |
o.SupportedWorkDoneProgressFormats = make(map[WorkDoneProgressStyle]bool, len(formats)) |
| 1099 |
for _, f := range formats { |
| 1100 |
o.SupportedWorkDoneProgressFormats[WorkDoneProgressStyle(f.(string))] = true |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
if interactiveCap, ok := experimental["interactiveResolve"].(map[string]any); ok { |
| 1105 |
if inputTypes, ok := interactiveCap["inputTypes"].([]any); ok { |
| 1106 |
o.SupportedInteractiveInputTypes = make(map[InteractiveInputType]bool, len(inputTypes)) |
| 1107 |
for _, t := range inputTypes { |
| 1108 |
if s, ok := t.(string); ok { |
| 1109 |
o.SupportedInteractiveInputTypes[InteractiveInputType(s)] = true |
| 1110 |
} |
| 1111 |
} |
| 1112 |
} |
| 1113 |
} |
| 1114 |
} |
| 1115 |
} |
| 1116 |
|
| 1117 |
var codec = frob.CodecFor[*Options]() |
| 1118 |
|
| 1119 |
func (o *Options) Clone() *Options { |
| 1120 |
return codec.Decode(codec.Encode(o)) |
| 1121 |
} |
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
func validateDirectoryFilter(ifilter string) (string, error) { |
| 1128 |
filter := fmt.Sprint(ifilter) |
| 1129 |
if filter == "" || (filter[0] != '+' && filter[0] != '-') { |
| 1130 |
return "", fmt.Errorf("invalid filter %v, must start with + or -", filter) |
| 1131 |
} |
| 1132 |
segs := strings.Split(filter[1:], "/") |
| 1133 |
unsupportedOps := [...]string{"?", "*"} |
| 1134 |
for _, seg := range segs { |
| 1135 |
if seg != "**" { |
| 1136 |
for _, op := range unsupportedOps { |
| 1137 |
if strings.Contains(seg, op) { |
| 1138 |
return "", fmt.Errorf("invalid filter %v, operator %v not supported. If you want to have this operator supported, consider filing an issue", filter, op) |
| 1139 |
} |
| 1140 |
} |
| 1141 |
} |
| 1142 |
} |
| 1143 |
|
| 1144 |
return strings.TrimRight(filepath.FromSlash(filter), "/"), nil |
| 1145 |
} |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
func (o *Options) setOne(name string, value any) (applied []CounterPath, _ error) { |
| 1163 |
switch name { |
| 1164 |
case "env": |
| 1165 |
env, ok := value.(map[string]any) |
| 1166 |
if !ok { |
| 1167 |
return nil, fmt.Errorf("invalid type %T (want JSON object)", value) |
| 1168 |
} |
| 1169 |
if o.Env == nil { |
| 1170 |
o.Env = make(map[string]string) |
| 1171 |
} |
| 1172 |
for k, v := range env { |
| 1173 |
|
| 1174 |
switch v.(type) { |
| 1175 |
case string, int: |
| 1176 |
o.Env[k] = fmt.Sprint(v) |
| 1177 |
default: |
| 1178 |
return nil, fmt.Errorf("invalid map value %T (want string)", v) |
| 1179 |
} |
| 1180 |
} |
| 1181 |
return nil, nil |
| 1182 |
|
| 1183 |
case "buildFlags": |
| 1184 |
return nil, setStringSlice(&o.BuildFlags, value) |
| 1185 |
|
| 1186 |
case "directoryFilters": |
| 1187 |
filterStrings, err := asStringSlice(value) |
| 1188 |
if err != nil { |
| 1189 |
return nil, err |
| 1190 |
} |
| 1191 |
var filters []string |
| 1192 |
for _, filterStr := range filterStrings { |
| 1193 |
filter, err := validateDirectoryFilter(filterStr) |
| 1194 |
if err != nil { |
| 1195 |
return nil, err |
| 1196 |
} |
| 1197 |
filters = append(filters, strings.TrimRight(filepath.FromSlash(filter), "/")) |
| 1198 |
} |
| 1199 |
o.DirectoryFilters = filters |
| 1200 |
return nil, nil |
| 1201 |
|
| 1202 |
case "workspaceFiles": |
| 1203 |
return nil, setStringSlice(&o.WorkspaceFiles, value) |
| 1204 |
case "completionDocumentation": |
| 1205 |
return setBool(&o.CompletionDocumentation, value) |
| 1206 |
case "usePlaceholders": |
| 1207 |
return setBool(&o.UsePlaceholders, value) |
| 1208 |
case "deepCompletion": |
| 1209 |
return setBool(&o.DeepCompletion, value) |
| 1210 |
case "completeUnimported": |
| 1211 |
return setBool(&o.CompleteUnimported, value) |
| 1212 |
case "completionBudget": |
| 1213 |
return nil, setDuration(&o.CompletionBudget, value) |
| 1214 |
case "importsSource": |
| 1215 |
res, err := setEnum(&o.ImportsSource, value, |
| 1216 |
ImportsSourceOff, |
| 1217 |
ImportsSourceGopls, |
| 1218 |
ImportsSourceGoimports) |
| 1219 |
if err != nil { |
| 1220 |
return nil, err |
| 1221 |
} |
| 1222 |
return res, &SoftError{ |
| 1223 |
msg: "importsSource is deprecated as it is no longer needed", |
| 1224 |
} |
| 1225 |
case "matcher": |
| 1226 |
return setEnum(&o.Matcher, value, |
| 1227 |
Fuzzy, |
| 1228 |
CaseSensitive, |
| 1229 |
CaseInsensitive) |
| 1230 |
|
| 1231 |
case "symbolMatcher": |
| 1232 |
return setEnum(&o.SymbolMatcher, value, |
| 1233 |
SymbolFuzzy, |
| 1234 |
SymbolFastFuzzy, |
| 1235 |
SymbolCaseInsensitive, |
| 1236 |
SymbolCaseSensitive) |
| 1237 |
|
| 1238 |
case "symbolStyle": |
| 1239 |
return setEnum(&o.SymbolStyle, value, |
| 1240 |
FullyQualifiedSymbols, |
| 1241 |
PackageQualifiedSymbols, |
| 1242 |
DynamicSymbols) |
| 1243 |
|
| 1244 |
case "symbolScope": |
| 1245 |
return setEnum(&o.SymbolScope, value, |
| 1246 |
WorkspaceSymbolScope, |
| 1247 |
AllSymbolScope) |
| 1248 |
|
| 1249 |
case "hoverKind": |
| 1250 |
|
| 1251 |
|
| 1252 |
return setEnum(&o.HoverKind, value, |
| 1253 |
NoDocumentation, |
| 1254 |
SingleLine, |
| 1255 |
SynopsisDocumentation, |
| 1256 |
FullDocumentation, |
| 1257 |
Structured, |
| 1258 |
) |
| 1259 |
|
| 1260 |
case "linkTarget": |
| 1261 |
return nil, setString(&o.LinkTarget, value) |
| 1262 |
|
| 1263 |
case "linksInHover": |
| 1264 |
switch value { |
| 1265 |
case false: |
| 1266 |
o.LinksInHover = LinksInHover_None |
| 1267 |
case true: |
| 1268 |
o.LinksInHover = LinksInHover_LinkTarget |
| 1269 |
case "gopls": |
| 1270 |
o.LinksInHover = LinksInHover_Gopls |
| 1271 |
default: |
| 1272 |
return nil, fmt.Errorf(`invalid value %s; expect false, true, or "gopls"`, value) |
| 1273 |
} |
| 1274 |
return nil, nil |
| 1275 |
|
| 1276 |
case "importShortcut": |
| 1277 |
return setEnum(&o.ImportShortcut, value, |
| 1278 |
BothShortcuts, |
| 1279 |
LinkShortcut, |
| 1280 |
DefinitionShortcut) |
| 1281 |
|
| 1282 |
case "analyses": |
| 1283 |
return setBoolMap(&o.Analyses, value) |
| 1284 |
|
| 1285 |
case "hints": |
| 1286 |
return setBoolMap(&o.Hints, value) |
| 1287 |
|
| 1288 |
case "annotations": |
| 1289 |
return setAnnotationMap(&o.Annotations, value) |
| 1290 |
|
| 1291 |
case "vulncheck": |
| 1292 |
return setEnum(&o.Vulncheck, value, |
| 1293 |
ModeVulncheckOff, |
| 1294 |
ModeVulncheckImports, |
| 1295 |
ModeVulncheckPrompt) |
| 1296 |
|
| 1297 |
case "codelenses", "codelens": |
| 1298 |
lensOverrides, err := asBoolMap[CodeLensSource](value) |
| 1299 |
if err != nil { |
| 1300 |
return nil, err |
| 1301 |
} |
| 1302 |
if o.Codelenses == nil { |
| 1303 |
o.Codelenses = make(map[CodeLensSource]bool) |
| 1304 |
} |
| 1305 |
o.Codelenses = maps.Clone(o.Codelenses) |
| 1306 |
maps.Copy(o.Codelenses, lensOverrides) |
| 1307 |
|
| 1308 |
var counts []CounterPath |
| 1309 |
for k, v := range lensOverrides { |
| 1310 |
counts = append(counts, CounterPath{string(k), fmt.Sprint(v)}) |
| 1311 |
} |
| 1312 |
|
| 1313 |
var errs []string |
| 1314 |
if name == "codelens" { |
| 1315 |
errs = append(errs, deprecatedError("codelenses").Error()) |
| 1316 |
} |
| 1317 |
if lensOverrides[CodeLensRunGovulncheck] && lensOverrides[CodeLensVulncheck] { |
| 1318 |
errs = append(errs, "The 'run_govulncheck' codelens is superseded by the 'vulncheck' codelens. Only 'vulncheck' should be set.") |
| 1319 |
} |
| 1320 |
if len(errs) > 0 { |
| 1321 |
return counts, &SoftError{msg: strings.Join(errs, "\n")} |
| 1322 |
} |
| 1323 |
return counts, nil |
| 1324 |
|
| 1325 |
case "staticcheck": |
| 1326 |
o.StaticcheckProvided = true |
| 1327 |
return setBool(&o.Staticcheck, value) |
| 1328 |
|
| 1329 |
case "local": |
| 1330 |
return nil, setString(&o.Local, value) |
| 1331 |
|
| 1332 |
case "maxFileCacheBytes": |
| 1333 |
return setInt64(&o.MaxFileCacheBytes, value) |
| 1334 |
|
| 1335 |
case "verboseOutput": |
| 1336 |
return setBool(&o.VerboseOutput, value) |
| 1337 |
|
| 1338 |
case "verboseWorkDoneProgress": |
| 1339 |
return setBool(&o.VerboseWorkDoneProgress, value) |
| 1340 |
|
| 1341 |
case "showBugReports": |
| 1342 |
return setBool(&o.ShowBugReports, value) |
| 1343 |
|
| 1344 |
case "gofumpt": |
| 1345 |
return setBool(&o.Gofumpt, value) |
| 1346 |
|
| 1347 |
case "completeFunctionCalls": |
| 1348 |
return setBool(&o.CompleteFunctionCalls, value) |
| 1349 |
|
| 1350 |
case "semanticTokens": |
| 1351 |
return setBool(&o.SemanticTokens, value) |
| 1352 |
|
| 1353 |
|
| 1354 |
case "noSemanticString": |
| 1355 |
counts, err := setBool(&o.NoSemanticString, value) |
| 1356 |
if err != nil { |
| 1357 |
return nil, err |
| 1358 |
} |
| 1359 |
return counts, &SoftError{"noSemanticString setting is deprecated, use semanticTokenTypes instead (though you can continue to apply them for the time being)."} |
| 1360 |
|
| 1361 |
case "noSemanticNumber": |
| 1362 |
counts, err := setBool(&o.NoSemanticNumber, value) |
| 1363 |
if err != nil { |
| 1364 |
return nil, err |
| 1365 |
} |
| 1366 |
return counts, &SoftError{"noSemanticNumber setting is deprecated, use semanticTokenTypes instead (though you can continue to apply them for the time being)."} |
| 1367 |
|
| 1368 |
case "semanticTokenTypes": |
| 1369 |
return setBoolMap(&o.SemanticTokenTypes, value) |
| 1370 |
|
| 1371 |
case "semanticTokenModifiers": |
| 1372 |
return setBoolMap(&o.SemanticTokenModifiers, value) |
| 1373 |
|
| 1374 |
case "newGoFileHeader": |
| 1375 |
return setBool(&o.NewGoFileHeader, value) |
| 1376 |
|
| 1377 |
case "expandWorkspaceToModule": |
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
return setBool(&o.ExpandWorkspaceToModule, value) |
| 1382 |
|
| 1383 |
case "experimentalPostfixCompletions": |
| 1384 |
return setBool(&o.ExperimentalPostfixCompletions, value) |
| 1385 |
|
| 1386 |
case "templateExtensions": |
| 1387 |
switch value := value.(type) { |
| 1388 |
case []any: |
| 1389 |
return nil, setStringSlice(&o.TemplateExtensions, value) |
| 1390 |
case nil: |
| 1391 |
o.TemplateExtensions = nil |
| 1392 |
default: |
| 1393 |
return nil, fmt.Errorf("unexpected type %T (want JSON array of string)", value) |
| 1394 |
} |
| 1395 |
return nil, nil |
| 1396 |
|
| 1397 |
case "diagnosticsDelay": |
| 1398 |
return nil, setDuration(&o.DiagnosticsDelay, value) |
| 1399 |
|
| 1400 |
case "diagnosticsTrigger": |
| 1401 |
return setEnum(&o.DiagnosticsTrigger, value, |
| 1402 |
DiagnosticsOnEdit, |
| 1403 |
DiagnosticsOnSave) |
| 1404 |
|
| 1405 |
case "analysisProgressReporting": |
| 1406 |
return setBool(&o.AnalysisProgressReporting, value) |
| 1407 |
|
| 1408 |
case "standaloneTags": |
| 1409 |
return nil, setStringSlice(&o.StandaloneTags, value) |
| 1410 |
|
| 1411 |
case "subdirWatchPatterns": |
| 1412 |
return setEnum(&o.SubdirWatchPatterns, value, |
| 1413 |
SubdirWatchPatternsOn, |
| 1414 |
SubdirWatchPatternsOff, |
| 1415 |
SubdirWatchPatternsAuto) |
| 1416 |
|
| 1417 |
case "reportAnalysisProgressAfter": |
| 1418 |
return nil, setDuration(&o.ReportAnalysisProgressAfter, value) |
| 1419 |
|
| 1420 |
case "telemetryPrompt": |
| 1421 |
return setBool(&o.TelemetryPrompt, value) |
| 1422 |
|
| 1423 |
case "linkifyShowMessage": |
| 1424 |
return setBool(&o.LinkifyShowMessage, value) |
| 1425 |
|
| 1426 |
case "includeReplaceInWorkspace": |
| 1427 |
return setBool(&o.IncludeReplaceInWorkspace, value) |
| 1428 |
|
| 1429 |
case "zeroConfig": |
| 1430 |
return setBool(&o.ZeroConfig, value) |
| 1431 |
|
| 1432 |
case "pullDiagnostics": |
| 1433 |
return setBool(&o.PullDiagnostics, value) |
| 1434 |
|
| 1435 |
case "mcpTools": |
| 1436 |
return setBoolMap(&o.MCPTools, value) |
| 1437 |
|
| 1438 |
case "renameMovesSubpackages": |
| 1439 |
return setBool(&o.RenameMovesSubpackages, value) |
| 1440 |
|
| 1441 |
case "fileWatcher": |
| 1442 |
return setEnum(&o.FileWatcher, value, FileWatcherOff, FileWatcherFSNotify, FileWatcherPoll) |
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
case "experimentalDisabledAnalyses": |
| 1452 |
return nil, deprecatedError("analyses") |
| 1453 |
|
| 1454 |
case "disableDeepCompletion": |
| 1455 |
return nil, deprecatedError("deepCompletion") |
| 1456 |
|
| 1457 |
case "disableFuzzyMatching": |
| 1458 |
return nil, deprecatedError("fuzzyMatching") |
| 1459 |
|
| 1460 |
case "wantCompletionDocumentation": |
| 1461 |
return nil, deprecatedError("completionDocumentation") |
| 1462 |
|
| 1463 |
case "wantUnimportedCompletions": |
| 1464 |
return nil, deprecatedError("completeUnimported") |
| 1465 |
|
| 1466 |
case "fuzzyMatching": |
| 1467 |
return nil, deprecatedError("matcher") |
| 1468 |
|
| 1469 |
case "caseSensitiveCompletion": |
| 1470 |
return nil, deprecatedError("matcher") |
| 1471 |
|
| 1472 |
case "experimentalDiagnosticsDelay": |
| 1473 |
return nil, deprecatedError("diagnosticsDelay") |
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
case "allowImplicitNetworkAccess": |
| 1478 |
return nil, deprecatedError("") |
| 1479 |
|
| 1480 |
case "memoryMode": |
| 1481 |
return nil, deprecatedError("") |
| 1482 |
|
| 1483 |
case "tempModFile": |
| 1484 |
return nil, deprecatedError("") |
| 1485 |
|
| 1486 |
case "experimentalWorkspaceModule": |
| 1487 |
return nil, deprecatedError("") |
| 1488 |
|
| 1489 |
case "experimentalTemplateSupport": |
| 1490 |
return nil, deprecatedError("") |
| 1491 |
|
| 1492 |
case "experimentalWatchedFileDelay": |
| 1493 |
return nil, deprecatedError("") |
| 1494 |
|
| 1495 |
case "experimentalPackageCacheKey": |
| 1496 |
return nil, deprecatedError("") |
| 1497 |
|
| 1498 |
case "allowModfileModifications": |
| 1499 |
return nil, deprecatedError("") |
| 1500 |
|
| 1501 |
case "allExperiments": |
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
return nil, nil |
| 1509 |
|
| 1510 |
case "experimentalUseInvalidMetadata": |
| 1511 |
return nil, deprecatedError("") |
| 1512 |
|
| 1513 |
case "newDiff": |
| 1514 |
return nil, deprecatedError("") |
| 1515 |
|
| 1516 |
case "wantSuggestedFixes": |
| 1517 |
return nil, deprecatedError("") |
| 1518 |
|
| 1519 |
case "noIncrementalSync": |
| 1520 |
return nil, deprecatedError("") |
| 1521 |
|
| 1522 |
case "watchFileChanges": |
| 1523 |
return nil, deprecatedError("") |
| 1524 |
|
| 1525 |
case "go-diff": |
| 1526 |
return nil, deprecatedError("") |
| 1527 |
|
| 1528 |
default: |
| 1529 |
return nil, fmt.Errorf("unexpected setting") |
| 1530 |
} |
| 1531 |
} |
| 1532 |
|
| 1533 |
|
| 1534 |
func (o *Options) EnabledSemanticTokenModifiers() map[semtok.Modifier]bool { |
| 1535 |
copy := make(map[semtok.Modifier]bool, len(o.SemanticTokenModifiers)) |
| 1536 |
for k, v := range o.SemanticTokenModifiers { |
| 1537 |
copy[semtok.Modifier(k)] = v |
| 1538 |
} |
| 1539 |
return copy |
| 1540 |
} |
| 1541 |
|
| 1542 |
|
| 1543 |
func (o *Options) EnabledSemanticTokenTypes() map[semtok.Type]bool { |
| 1544 |
copy := make(map[semtok.Type]bool, len(o.SemanticTokenTypes)) |
| 1545 |
for k, v := range o.SemanticTokenTypes { |
| 1546 |
copy[semtok.Type(k)] = v |
| 1547 |
} |
| 1548 |
if o.NoSemanticString { |
| 1549 |
copy[semtok.TokString] = false |
| 1550 |
} |
| 1551 |
if o.NoSemanticNumber { |
| 1552 |
copy[semtok.TokNumber] = false |
| 1553 |
} |
| 1554 |
return copy |
| 1555 |
} |
| 1556 |
|
| 1557 |
|
| 1558 |
type SoftError struct { |
| 1559 |
msg string |
| 1560 |
} |
| 1561 |
|
| 1562 |
func (e *SoftError) Error() string { |
| 1563 |
return e.msg |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
func deprecatedError(replacement string) error { |
| 1569 |
msg := "this setting is deprecated" |
| 1570 |
if replacement != "" { |
| 1571 |
msg = fmt.Sprintf("%s, use %q instead", msg, replacement) |
| 1572 |
} |
| 1573 |
return &SoftError{msg} |
| 1574 |
} |
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
func setBool(dest *bool, value any) ([]CounterPath, error) { |
| 1580 |
b, err := asBool(value) |
| 1581 |
if err != nil { |
| 1582 |
return nil, err |
| 1583 |
} |
| 1584 |
*dest = b |
| 1585 |
return []CounterPath{{fmt.Sprint(b)}}, nil |
| 1586 |
} |
| 1587 |
|
| 1588 |
func asBool(value any) (bool, error) { |
| 1589 |
b, ok := value.(bool) |
| 1590 |
if !ok { |
| 1591 |
return false, fmt.Errorf("invalid type %T (want bool)", value) |
| 1592 |
} |
| 1593 |
return b, nil |
| 1594 |
} |
| 1595 |
|
| 1596 |
func setDuration(dest *time.Duration, value any) error { |
| 1597 |
str, err := asString(value) |
| 1598 |
if err != nil { |
| 1599 |
return err |
| 1600 |
} |
| 1601 |
parsed, err := time.ParseDuration(str) |
| 1602 |
if err != nil { |
| 1603 |
return err |
| 1604 |
} |
| 1605 |
*dest = parsed |
| 1606 |
return nil |
| 1607 |
} |
| 1608 |
|
| 1609 |
func setAnnotationMap(dest *map[Annotation]bool, value any) ([]CounterPath, error) { |
| 1610 |
all, err := asBoolMap[string](value) |
| 1611 |
if err != nil { |
| 1612 |
return nil, err |
| 1613 |
} |
| 1614 |
var counters []CounterPath |
| 1615 |
|
| 1616 |
m := make(map[Annotation]bool) |
| 1617 |
for k, enabled := range all { |
| 1618 |
var a Annotation |
| 1619 |
cnts, err := setEnum(&a, k, |
| 1620 |
Nil, |
| 1621 |
Escape, |
| 1622 |
Inline, |
| 1623 |
Bounds) |
| 1624 |
if err != nil { |
| 1625 |
|
| 1626 |
switch k { |
| 1627 |
case "noEscape": |
| 1628 |
m[Escape] = false |
| 1629 |
return nil, fmt.Errorf(`"noEscape" is deprecated, set "Escape: false" instead`) |
| 1630 |
|
| 1631 |
case "noNilcheck": |
| 1632 |
m[Nil] = false |
| 1633 |
return nil, fmt.Errorf(`"noNilcheck" is deprecated, set "Nil: false" instead`) |
| 1634 |
|
| 1635 |
case "noInline": |
| 1636 |
m[Inline] = false |
| 1637 |
return nil, fmt.Errorf(`"noInline" is deprecated, set "Inline: false" instead`) |
| 1638 |
|
| 1639 |
case "noBounds": |
| 1640 |
m[Bounds] = false |
| 1641 |
return nil, fmt.Errorf(`"noBounds" is deprecated, set "Bounds: false" instead`) |
| 1642 |
|
| 1643 |
default: |
| 1644 |
return nil, err |
| 1645 |
} |
| 1646 |
} |
| 1647 |
counters = append(counters, cnts...) |
| 1648 |
m[a] = enabled |
| 1649 |
} |
| 1650 |
*dest = m |
| 1651 |
return counters, nil |
| 1652 |
} |
| 1653 |
|
| 1654 |
func setBoolMap[K ~string](dest *map[K]bool, value any) ([]CounterPath, error) { |
| 1655 |
m, err := asBoolMap[K](value) |
| 1656 |
if err != nil { |
| 1657 |
return nil, err |
| 1658 |
} |
| 1659 |
*dest = m |
| 1660 |
var counts []CounterPath |
| 1661 |
for k, v := range m { |
| 1662 |
counts = append(counts, CounterPath{string(k), fmt.Sprint(v)}) |
| 1663 |
} |
| 1664 |
return counts, nil |
| 1665 |
} |
| 1666 |
|
| 1667 |
func asBoolMap[K ~string](value any) (map[K]bool, error) { |
| 1668 |
all, ok := value.(map[string]any) |
| 1669 |
if !ok { |
| 1670 |
return nil, fmt.Errorf("invalid type %T (want JSON object)", value) |
| 1671 |
} |
| 1672 |
m := make(map[K]bool) |
| 1673 |
for a, enabled := range all { |
| 1674 |
b, ok := enabled.(bool) |
| 1675 |
if !ok { |
| 1676 |
return nil, fmt.Errorf("invalid type %T for object field %q", enabled, a) |
| 1677 |
} |
| 1678 |
m[K(a)] = b |
| 1679 |
} |
| 1680 |
return m, nil |
| 1681 |
} |
| 1682 |
|
| 1683 |
func setString(dest *string, value any) error { |
| 1684 |
str, err := asString(value) |
| 1685 |
if err != nil { |
| 1686 |
return err |
| 1687 |
} |
| 1688 |
*dest = str |
| 1689 |
return nil |
| 1690 |
} |
| 1691 |
|
| 1692 |
func asString(value any) (string, error) { |
| 1693 |
str, ok := value.(string) |
| 1694 |
if !ok { |
| 1695 |
return "", fmt.Errorf("invalid type %T (want string)", value) |
| 1696 |
} |
| 1697 |
return str, nil |
| 1698 |
} |
| 1699 |
|
| 1700 |
func setStringSlice(dest *[]string, value any) error { |
| 1701 |
slice, err := asStringSlice(value) |
| 1702 |
if err != nil { |
| 1703 |
return err |
| 1704 |
} |
| 1705 |
*dest = slice |
| 1706 |
return nil |
| 1707 |
} |
| 1708 |
|
| 1709 |
func asStringSlice(value any) ([]string, error) { |
| 1710 |
array, ok := value.([]any) |
| 1711 |
if !ok { |
| 1712 |
return nil, fmt.Errorf("invalid type %T (want JSON array of string)", value) |
| 1713 |
} |
| 1714 |
var slice []string |
| 1715 |
for _, elem := range array { |
| 1716 |
str, ok := elem.(string) |
| 1717 |
if !ok { |
| 1718 |
return nil, fmt.Errorf("invalid array element type %T (want string)", elem) |
| 1719 |
} |
| 1720 |
slice = append(slice, str) |
| 1721 |
} |
| 1722 |
return slice, nil |
| 1723 |
} |
| 1724 |
|
| 1725 |
func setEnum[S ~string](dest *S, value any, options ...S) ([]CounterPath, error) { |
| 1726 |
enum, err := asEnum(value, options...) |
| 1727 |
if err != nil { |
| 1728 |
return nil, err |
| 1729 |
} |
| 1730 |
*dest = enum |
| 1731 |
return []CounterPath{{string(enum)}}, nil |
| 1732 |
} |
| 1733 |
|
| 1734 |
func asEnum[S ~string](value any, options ...S) (S, error) { |
| 1735 |
str, err := asString(value) |
| 1736 |
if err != nil { |
| 1737 |
return "", err |
| 1738 |
} |
| 1739 |
for _, opt := range options { |
| 1740 |
if strings.EqualFold(str, string(opt)) { |
| 1741 |
return opt, nil |
| 1742 |
} |
| 1743 |
} |
| 1744 |
return "", fmt.Errorf("invalid option %q for enum", str) |
| 1745 |
} |
| 1746 |
|
| 1747 |
func setInt64(dest *int64, value any) ([]CounterPath, error) { |
| 1748 |
i, err := asInt64(value) |
| 1749 |
if err != nil { |
| 1750 |
return nil, err |
| 1751 |
} |
| 1752 |
*dest = i |
| 1753 |
return []CounterPath{{fmt.Sprint(i)}}, nil |
| 1754 |
} |
| 1755 |
|
| 1756 |
func asInt64(value any) (int64, error) { |
| 1757 |
switch v := value.(type) { |
| 1758 |
|
| 1759 |
case float64: |
| 1760 |
|
| 1761 |
|
| 1762 |
if !isFinite(v) { |
| 1763 |
return 0, fmt.Errorf("invalid value %v (want finite number)", v) |
| 1764 |
} |
| 1765 |
if v != math.Trunc(v) { |
| 1766 |
return 0, fmt.Errorf("invalid value %v (want integer)", v) |
| 1767 |
} |
| 1768 |
if v != float64(int64(v)) { |
| 1769 |
return 0, fmt.Errorf("invalid value %v (not representable as int64)", v) |
| 1770 |
} |
| 1771 |
return int64(v), nil |
| 1772 |
case int64: |
| 1773 |
return v, nil |
| 1774 |
case int: |
| 1775 |
return int64(v), nil |
| 1776 |
default: |
| 1777 |
return 0, fmt.Errorf("invalid type %T (want int64)", value) |
| 1778 |
} |
| 1779 |
} |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
func isFinite(f float64) bool { |
| 1784 |
return math.Abs(f) <= math.MaxFloat64 |
| 1785 |
} |