Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to enable unnecessaryParenthesesAnalyzer #79

Closed
AntonStrand opened this issue Apr 30, 2024 · 5 comments
Closed

Add the option to enable unnecessaryParenthesesAnalyzer #79

AntonStrand opened this issue Apr 30, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@AntonStrand
Copy link

Is your feature request related to a problem? Please describe.
FsAutocomplete added a setting unnecessaryParenthesesAnalyzer two months ago. It would be nice to be able to enable this setting. ionide/FsAutoComplete#1235

Describe the solution you'd like
The optimal solution would be to add all settings the VSCode has. I would lie if I said that I've gone through all settings to check which are missing so it just might be this setting that is missing.

Describe alternatives you've considered
I would be fine with just adding unnecessaryParenthesesAnalyzer. Or, is there a workaround that I can do in my Neovim settings to enable me to set this setting in another way?

Additional context

@AntonStrand AntonStrand added the enhancement New feature or request label Apr 30, 2024
@greggyb
Copy link
Contributor

greggyb commented May 18, 2024

@cannorin I'd be willing to take this on with some pointers on where to get started. I peaked through the source a bit, and it seems that code actions are entirely delegated to the LSP client and the language server. I see where the default settings are defined in autoload/fsharp.vim, but grepping the code base for existing lints and code actions yields nothing.

Is this something that would need to be configured in the tools' own configs (fsautocomplete or fsharplint)?

@baronfel
Copy link

baronfel commented May 18, 2024

@greggyb in the general case what you need is a way for users to set some config settings and have those applied to the LSP settings that are sent to the LSP. This sending happens in two places:

  • The initialize LSP call when FSAC is started by ionide-vim
  • The workspace/didChangeConfiguration call, which should be set any time the user changes any settings which could impact the LSP.

What we've done in Ionide for VsCode is add all of the settings for FSAC to settings for the VSCode extension, and when a user edits these at all then the editor handles sending the necessary workspace/didChangeConfiguration LSP call to FSAC. I'm not sure what the exact parallels are here, but I think you should be looking for something similar. I don't think there should be any change to any other tool at this time.

@greggyb
Copy link
Contributor

greggyb commented May 18, 2024

So I've got a one-line change that will add this specific setting. We've got some divergence between the options in Ionide-vim and fsautocomplete. Lists below. Anything that is a primitive or primitive collection seems straightforward to add, here. I'd have to dig further to see what it would take to reasonably serialize some of these other types in a Vim data structure.

All it takes to add support for the option is to add an entry to the array s:config_keys_camel (excerpted below). This array is then looped over in a couple of places to build up a configuration to send to the language server on initialization and update.

@cannorin , would you prefer a one-liner change for a PR, or would it be better to add all of these options in one go?

Supported in FsAutocomplete (FsharpConfigDto) 47 lines.

  { AutomaticWorkspaceInit: bool option
    WorkspaceModePeekDeepLevel: int option
    ExcludeProjectDirectories: string array option
    KeywordsAutocomplete: bool option
    ExternalAutocomplete: bool option
    FullNameExternalAutocomplete: bool option
    Linter: bool option
    LinterConfig: string option
    IndentationSize: int option
    UnionCaseStubGeneration: bool option
    UnionCaseStubGenerationBody: string option
    RecordStubGeneration: bool option
    RecordStubGenerationBody: string option
    InterfaceStubGeneration: bool option
    InterfaceStubGenerationObjectIdentifier: string option
    InterfaceStubGenerationMethodBody: string option
    AddPrivateAccessModifier: bool option
    UnusedOpensAnalyzer: bool option
    UnusedOpensAnalyzerExclusions: string array option
    UnusedDeclarationsAnalyzer: bool option
    UnusedDeclarationsAnalyzerExclusions: string array option
    SimplifyNameAnalyzer: bool option
    SimplifyNameAnalyzerExclusions: string array option
    UnnecessaryParenthesesAnalyzer: bool option
    ResolveNamespaces: bool option
    EnableReferenceCodeLens: bool option
    EnableAnalyzers: bool option
    AnalyzersPath: string array option
    ExcludeAnalyzers: string array option
    IncludeAnalyzers: string array option
    DisableInMemoryProjectReferences: bool option
    LineLens: LineLensConfig option
    UseSdkScripts: bool option
    DotNetRoot: string option
    FSIExtraParameters: string array option
    FSICompilerToolLocations: string array option
    TooltipMode: string option
    GenerateBinlog: bool option
    AbstractClassStubGeneration: bool option
    AbstractClassStubGenerationObjectIdentifier: string option
    AbstractClassStubGenerationMethodBody: string option
    CodeLenses: CodeLensConfigDto option
    PipelineHints: InlineValueDto option
    InlayHints: InlayHintDto option
    Fsac: FSACDto option
    Notifications: NotificationsDto option
    Debug: DebugDto option }

Supported in Ionide-vim (from autoload/fsharp.vim). 26 lines of options (including my added line for the unnecessary parentheses option, so 25 before adding this):

let s:config_keys_camel =
    \ [
    \     {'key': 'AutomaticWorkspaceInit', 'default': 1},
    \     {'key': 'WorkspaceModePeekDeepLevel', 'default': 2},
    \     {'key': 'ExcludeProjectDirectories', 'default': []},
    \     {'key': 'keywordsAutocomplete', 'default': 1},
    \     {'key': 'ExternalAutocomplete', 'default': 0},
    \     {'key': 'Linter', 'default': 1},
    \     {'key': 'UnionCaseStubGeneration', 'default': 1},
    \     {'key': 'UnionCaseStubGenerationBody'},
    \     {'key': 'RecordStubGeneration', 'default': 1},
    \     {'key': 'RecordStubGenerationBody'},
    \     {'key': 'InterfaceStubGeneration', 'default': 1},
    \     {'key': 'InterfaceStubGenerationObjectIdentifier', 'default': 'this'},
    \     {'key': 'InterfaceStubGenerationMethodBody'},
    \     {'key': 'UnusedOpensAnalyzer', 'default': 1},
    \     {'key': 'UnusedDeclarationsAnalyzer', 'default': 1},
    \     {'key': 'SimplifyNameAnalyzer', 'default': 0},
    \     {'key': 'ResolveNamespaces', 'default': 1},
    \     {'key': 'EnableReferenceCodeLens', 'default': 1},
    \     {'key': 'EnableAnalyzers', 'default': 0},
    \     {'key': 'AnalyzersPath'},
    \     {'key': 'DisableInMemoryProjectReferences', 'default': 0},
    \     {'key': 'LineLens', 'default': {'enabled': 'never', 'prefix': ''}},
    \     {'key': 'UseSdkScripts', 'default': 1},
    \     {'key': 'dotNetRoot'},
    \     {'key': 'fsiExtraParameters', 'default': []},
    \     {'key': 'UnnecessaryParenthesesAnalyzer', 'default': 1},

@cannorin
Copy link
Member

@greggyb I would really appreciate it if you could add the missing options which are straightforward to add (i.e. primitive or primitive collection). I'll take care of the harder ones :)

greggyb added a commit to greggyb/Ionide-vim that referenced this issue May 21, 2024
Options taken from ionide/FsAutoComplete project, specifically
src/FsAutoComplete/LspHelpers.fs:
- names from `FSharpConfigDto`
- default values from `FSharpConfig.Default`

Brought over all that were primitives or primitive collections and
included commented TODO items for non-primitive options.

 implements ionide#79
@cannorin
Copy link
Member

@greggyb Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants