lsp icon indicating copy to clipboard operation
lsp copied to clipboard

Assistance with adding sonarlint-ls support

Open jclsn opened this issue 2 months ago • 7 comments

Trying to use sonarlint-ls with lsp

There exists a coc plugin and I have tried to the same arguments from here

This is what I have so far

        \ #{name: 'sonarlint-ls',
        \   filetype: ['c', 
        \              'cpp', 
        \              'go', 
        \              'html',  
        \              'java',
        \              'javascript', 
        \              'php', 
        \              'python',
        \              'terraform',
        \              'xml'],
        \   path: '/usr/bin/sonarlint-ls',
        \   args: [
        \          '-stdio', 
        \          '-analyzers', 
        \          '/usr/share/java/sonarlint-ls/analyzers/sonarcfamily.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonargo.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonarhtml.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonariac.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonarjava.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonarjs.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonarlintomnisharp.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonarphp.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonarpython.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonartext.jar',
        \          '/usr/share/java/sonarlint-ls/analyzers/sonarxml.jar',
        \   ],
        \   debug: v:true,
        \   syncInit: v:true,
	\   initializationOptions: #{
        \       sonarlint: #{
        \         pathToCompileCommands: './build/compile_commands.json'
        \       }
	\   }
	\   }
        \ },

It starts up fine. Sonarlint needs to be informed about the compile_commands.json somehow. No idea how to do that in lsp. For coc I would add this

"sonarlint.pathToCompileCommands": "${workspaceFolder}/build/compile_commands.json"

Server and debug output:

Server messages:

'/usr/bin/sonarlint-ls' Language Server Messages
================================================
05/26/24 08:48:08: [Log]: [Info  - 08:48:08.328] SonarLint backend started, instance=org.sonarsource.sonarlint.core.rpc.impl.SonarLintRpcServerImpl@6bd61f98
05/26/24 08:48:08: [Log]: [Debug - 08:48:08.418] Folder WorkspaceFolder[name=constexpr,uri=file:///home/jan/Workspace/constexpr/] added
05/26/24 08:49:08: [Log]: [Error - 08:49:08.420] Failed to initialize workspace folders

Debug messages:

05/27/24 16:44:21: Sent {'method': 'initialize', 'params': {'rootUri': 'file:///home/jan/Workspace/constexpr/', 'initializationOptions': {'sonarlint': {'pathToCompileCommands': './build/compile_commands.json'}}, 'workspaceFolders': [{'uri': 'file:///home/jan/Workspace/constexpr/', 'name': 'constexpr'}], 'rootPath': '/home/jan/Workspace/constexpr', 'clientInfo': {'version': '9010429', 'name': 'Vim'}, 'processId': 169055, 'trace': 'off', 'capabilities': {'workspace': {'workspaceFolders': true, 'configuration': true, 'workspaceEdit': {'resourceOperations': ['rename', 'create', 'delete']}, 'symbol': {'dynamicRegistration': false}, 'applyEdit': true}, 'offsetEncoding': ['utf-32', 'utf-16', 'utf-8'], 'window': {}, 'general': {'positionEncodings': ['utf-32', 'utf-16', 'utf-8']}, 'textDocument': {'callHierarchy': {'dynamicRegistration': false}, 'rename': {'prepareSupport': false, 'dynamicRegistration': false}, 'codeAction': {'isPreferredSupport': true, 'disabledSupport': true, 'codeActionLiteralSupport': {'codeActionKind': {'valueSet': ['', 'quickfix', 'refactor', 'refactor.extract', 'refactor.inline', 'refactor.rewrite', 'source', 'source.organizeImports']}}, 'dynamicRegistration': false}, 'completion': {'completionItem': {'insertReplaceSupport': false, 'snippetSupport': true, 'resolveSupport': {'properties': ['detail', 'documentation']}, 'documentationFormat': ['markdown', 'plaintext']}, 'dynamicRegistration': false, 'completionItemKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}}, 'formatting': {'dynamicRegistration': false}, 'codeLens': {'dynamicRegistration': false}, 'inlayHint': {'dynamicRegistration': false}, 'hover': {'dynamicRegistration': false, 'contentFormat': ['markdown', 'plaintext']}, 'rangeFormatting': {'dynamicRegistration': false}, 'declaration': {'dynamicRegistration': false, 'linkSupport': true}, 'references': {'dynamicRegistration': false}, 'selectionRange': {'dynamicRegistration': false}, 'typeHierarchy': {'dynamicRegistration': false}, 'foldingRange': {'rangeLimit': 5000, 'foldingRange': {'collapsedText': true}, 'dynamicRegistration': false, 'foldingRangeKind': {'valueSet': ['comment', 'imports', 'region']}, 'lineFoldingOnly': true}, 'documentSymbol': {'symbolKind': {'valueSet': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}, 'dynamicRegistration': false, 'labelSupport': false, 'hierarchicalDocumentSymbolSupport': true}, 'publishDiagnostics': {'dataSupport': true, 'relatedInformation': false, 'codeDescriptionSupport': true, 'versionSupport': true}, 'synchronization': {'didSave': true, 'WillSaveWaitUntil': false, 'willSave': false, 'dynamicRegistration': false}, 'documentHighlight': {'dynamicRegistration': false}, 'implementation': {'dynamicRegistration': false, 'linkSupport': true}, 'typeDefinition': {'dynamicRegistration': false, 'linkSupport': true}, 'semanticTokens': {'serverCancelSupport': false, 'requests': {'full': {'delta': true}, 'range': false}, 'multilineTokenSupport': false, 'dynamicRegistration': false, 'overlappingTokenSupport': false, 'tokenTypes': ['type', 'class', 'enum', 'interface', 'struct', 'typeParameter', 'parameter', 'variable', 'property', 'enumMember', 'event', 'function', 'method', 'macro', 'keyword', 'modifier', 'comment', 'string', 'number', 'regexp', 'operator'], 'tokenModifiers': ['declaration', 'definition', 'readonly', 'static', 'deprecated', 'abstract', 'async', 'modification', 'documentation', 'defaultLibrary'], 'formats': ['relative'], 'augmentsSyntaxTokens': true}, 'signatureHelp': {'signatureInformation': {'activeParameterSupport': true, 'documentationFormat': ['markdown', 'plaintext']}, 'dynamicRegistration': false}, 'definition': {'dynamicRegistration': false, 'linkSupport': true}}}}}
05/27/24 16:44:22: Received {'method': 'window/logMessage', 'jsonrpc': '2.0', 'params': {'message': '[Info  - 16:44:22.554] SonarLint backend started, instance=org.sonarsource.sonarlint.core.rpc.impl.SonarLintRpcServerImpl@6bd61f98', 'type': 4}}
05/27/24 16:44:22: Received {'method': 'window/logMessage', 'jsonrpc': '2.0', 'params': {'message': '[Debug - 16:44:22.642] Folder WorkspaceFolder[name=constexpr,uri=file:///home/jan/Workspace/constexpr/] added', 'type': 4}}
05/27/24 16:44:22: Received {'id': 1, 'jsonrpc': '2.0', 'result': {'capabilities': {'executeCommandProvider': {'workDoneProgress': true, 'commands': ['SonarLint.QuickFixApplied', 'SonarLint.OpenRuleDescCodeAction', 'SonarLint.OpenStandaloneRuleDesc', 'SonarLint.BrowseTaintVulnerability', 'SonarLint.ShowTaintVulnerabilityFlows']}, 'workspace': {'workspaceFolders': {'changeNotifications': true, 'supported': true}}, 'codeActionProvider': true, 'textDocumentSync': {'change': 1, 'openClose': true}}, 'serverInfo': {'version': '3.5.1.75119', 'name': 'SonarLint Language Server'}}}
05/27/24 16:44:22: Received {'id': '1', 'jsonrpc': '2.0', 'method': 'sonarlint/shouldAnalyseFile', 'params': {'uri': 'file:///home/jan/Workspace/constexpr/constexpr.cpp'}}
05/27/24 16:45:22: Received {'method': 'window/logMessage', 'jsonrpc': '2.0', 'params': {'message': '[Error - 16:45:22.644] Failed to initialize workspace folders', 'type': 4}}
05/27/24 16:45:42: Received {'id': '2', 'jsonrpc': '2.0', 'method': 'sonarlint/shouldAnalyseFile', 'params': {'uri': 'file:///home/jan/Workspace/constexpr/constexpr.cpp'}}
05/27/24 16:45:44: Received {'id': '3', 'jsonrpc': '2.0', 'method': 'sonarlint/shouldAnalyseFile', 'params': {'uri': 'file:///home/jan/Workspace/constexpr/constexpr.cpp'}}

or here in a pastebin: https://0x0.st/XZFy.txt

jclsn avatar May 25 '24 11:05 jclsn