Simplify completion provider control flow - #6
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZXWCPHc3Vxctdtm0Fz8 for typescript:S3776 rule - AZXWCPHc3Vxctdtm0Fz9 for typescript:S6582 rule - AZXWCPHc3Vxctdtm0Fz5 for typescript:S3776 rule Generated by SonarQube Agent (task: 5dcdaae4-d5f1-49a8-b1de-fb2fab07761d)
SonarQube reviewer guideSummary: Refactor completion provider to improve code maintainability by extracting nested logic into smaller, focused helper functions. Review Focus:
Start review at:
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Refactored the Ansible language server completion provider to flatten nested logic and split complex resolution paths into smaller helpers. This reduces cognitive complexity in the affected functions and also replaces a manual null check with a more concise optional-chain style guard.
View Project in SonarCloud
Fixed Issues
typescript:S3776 - Refactor this function to reduce its Cognitive Complexity from 89 to the 15 allowed. • CRITICAL • View issue
Location:
packages/ansible-language-server/src/providers/completionProvider.ts:59Why is this an issue?
Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code. Code with high cognitive complexity is hard to read, understand, test, and modify.
What changed
This hunk adds an early return when path is missing, instead of nesting the rest of doCompletion inside if (path). That directly helps the reported high cognitive complexity in doCompletion by flattening control flow and removing one nesting level from the whole function.
typescript:S3776 - Refactor this function to reduce its Cognitive Complexity from 32 to the 15 allowed. • CRITICAL • View issue
Location:
packages/ansible-language-server/src/providers/completionProvider.ts:517Why is this an issue?
Cognitive Complexity is a measure of how hard it is to understand the control flow of a unit of code. Code with high cognitive complexity is hard to read, understand, test, and modify.
What changed
This hunk replaces the large inline body of doCompletionResolve with calls to smaller helpers and an immediate return. That is the main structural step in fixing the reported excessive cognitive complexity in doCompletionResolve.
typescript:S6582 - Prefer using an optional chain expression instead, as it's more concise and easier to read. • MAJOR • View issue
Location:
packages/ansible-language-server/src/providers/completionProvider.ts:529Why is this an issue?
Optional chaining allows to safely access nested properties or methods of an object without having to check for the existence of each intermediate property manually. It provides a concise and safe way to access nested properties or methods without having to write complex and error-prone
null/undefinedchecks.What changed
This hunk replaces the compound check for moduleFqcn and documentUri with an early guard inside the extracted helper. That helps the cognitive-complexity problem by flattening control flow, and it also addresses the warning about preferring optional chaining over manual logical checks because it removes the style of condition flagged around module && module.documentation logic and related nested checks.
SonarQube Remediation Agent uses AI. Check for mistakes.