Skip to content

Highlight related identifiers for control flow keywords #2400

@ahoppen

Description

@ahoppen

When inside a function, closure, or loop, I regularly find myself wondering which control flow constructs can terminate it. To assist me with that, SourceKit-LSP should return control flow keywords that exit from the same construct in the textDocument/documentHighlight request. For example in the following, the document highlight for throw or one of the return statements should return the other two keywords that leave the function scope.

func foo(x: Int) throws -> String {
  if x < 0 {
    throw ValueNegativeError()
  }
  if x == 0 {
    return "none"
  } else {
    return "many"
  }
}

The same can also apply to loops (break + continue).

To implement this, we’d likely need to implement a query in swift-syntax’s SwiftLexicalLookup library that returns the control flow construct (function, closure, loop) to which one of these statements belongs and then use that in SourceKit-LSP to compute the related control flow statements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions