Closed Bug 1895160 Opened 1 year ago Closed 1 year ago

Reflect the forward declaration and the single-line function definition to the selected symbol

Categories

(Webtools :: Searchfox, enhancement)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: arai, Assigned: arai)

Details

Attachments

(1 file)

Currently the "Symbol Link" feature uses the DocumentTitler.selectedSymbol, which uses the nesting container's symbol.
This means the symbol is not used for the following cases:

  • the function definition is single line
  • the forward declaration

I often use the "Symbol Link" feature to create a link to the function while explanation, but sometimes hit the above case, where I need to manually copy the function name.
It would be nice if those cases are also reflected to the selected symbol, so that the "Symbol Link" works for more cases.

The current design is the following:

  1. given a set of lines, find the deepest nesting container
  2. in the nesting container, find the corresponding source line
  3. return a symbol in the line

https://github.com/mozsearch/mozsearch/blob/6c186d2bea502a5d9e8911c3d91ba5a96ede33dd/static/js/code-highlighter.js#L238-L255

  processLineSelection(selectedLines) {
...
      const nestingContainer = this._findNestingContainerFor(selectedLines);
      const nestingLine = nestingContainer?.querySelector(
        ".nesting-sticky-line"
      );
      const sourceLine = nestingLine?.querySelector(".source-line");
      const bestPretty = this._findBestPrettySymbolInSourceLineElem(sourceLine);
      this.selectionTitle = bestPretty.short;
      this.selectedSymbol = bestPretty.long;
    }

This doesn't work for function definition with single line because the nesting container is not created for single line definition, because the block is closed in the same line.
In the same way, this doesn't work for the forward declaration also because the nesting container is not created, because forward declaration doesn't have a block.

Possible option is the following:

  1. given a set of line numbers, find the deepest nesting container
  2. given the set of line numbers, find the corresponding source lines
  3. find a first symbol in the source lines inside the deepest nesting container
  4. if there is such symbol, then
    1. return the symbol
  5. otherwise,
    1. in the nesting container, find the corresponding source line
    2. return a symbol in the line

This way, the single-line function definition and forward declaration also get reflected to the selected symbol,
and also a container is used when the selected lines don't contain any symbol.

Attached file GitHub Pull Request
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: