in src/ulsp/mapper/lsp_lifecycle.go [25:63]
func InitializeResultAppendCodeActionProvider(initResult *protocol.InitializeResult, newOptions *protocol.CodeActionOptions) error {
if initResult.Capabilities.CodeActionProvider == nil {
initResult.Capabilities.CodeActionProvider = newOptions
return nil
}
currentCodeActionOptions, ok := initResult.Capabilities.CodeActionProvider.(*protocol.CodeActionOptions)
if !ok {
return errors.New("CodeActionProvider does not match expected type of *protocol.CodeActionOptions")
}
if newOptions.CodeActionKinds != nil {
if currentCodeActionOptions.CodeActionKinds == nil {
// If the current CodeActionKinds is nil, just set it to the new value.
currentCodeActionOptions.CodeActionKinds = newOptions.CodeActionKinds
} else {
// Otherwise, add values that are not already present in the current CodeActionKinds.
seen := map[protocol.CodeActionKind]interface{}{}
combined := []protocol.CodeActionKind{}
for _, action := range currentCodeActionOptions.CodeActionKinds {
seen[action] = struct{}{}
combined = append(combined, action)
}
for _, action := range newOptions.CodeActionKinds {
if _, ok := seen[action]; !ok {
combined = append(combined, action)
}
}
currentCodeActionOptions.CodeActionKinds = combined
}
}
if newOptions.ResolveProvider == true {
currentCodeActionOptions.ResolveProvider = true
}
initResult.Capabilities.CodeActionProvider = currentCodeActionOptions
return nil
}