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

definition: Reveal import first #111

Open
zardoy opened this issue Mar 2, 2023 · 2 comments
Open

definition: Reveal import first #111

zardoy opened this issue Mar 2, 2023 · 2 comments
Labels
low-priority Not in my personal plan/roadmap. Pr still welcome!

Comments

@zardoy
Copy link
Owner

zardoy commented Mar 2, 2023

Configuration:

/**
 * Reveal import definition first, and then ctrl+click on import definition again to show the actual definition.
 * @default false
 */
revealImportDefinitionFirst: boolean

should be really easy to impl: when enabled:

const node = findChildContainingExactPosition(program.getSourceFile(fileName)!, position)!
const symbolAtLocation = program.getTypeChecker()!.getSymbolAtLocation(node)

Then with symbolAtLocation.declarations[0] do these checks:

let importDeclaration: ts.ImportDeclaration | undefined
if (ts.isImportSpecifier(node) && ts.isNamedImports(node.parent) && ts.isImportDeclaration(node.parent.parent.parent)) {
importDeclaration = node.parent.parent.parent
} else if (ts.isImportClause(node) && ts.isImportDeclaration(node.parent)) {
importDeclaration = node.parent
} else if (ts.isNamespaceImport(node) && ts.isImportClause(node.parent) && ts.isImportDeclaration(node.parent.parent)) {
// todo-low(builtin) maybe reformat text
importDeclaration = node.parent.parent
}
if (importDeclaration) {
prevCompletionsMap[entry.name] ??= {}
let importPath = importDeclaration.moduleSpecifier.getText()
const symbolsLimit = 40
if (importPath.length > symbolsLimit) importPath = importPath.slice(0, symbolsLimit / 2) + '...' + importPath.slice(-symbolsLimit / 2)
const detailPrepend = displayImportedInfo === 'short-format' ? `(from ${importPath}) ` : `Imported from ${importPath}\n\n`
prevCompletionsMap[entry.name]!.detailPrepend = detailPrepend
}

@zardoy zardoy added the low-priority Not in my personal plan/roadmap. Pr still welcome! label Mar 2, 2023
@tjx666
Copy link

tjx666 commented May 24, 2024

I find recently I want to use this feature more frequently. Current solution can't satisfy me now:

{
        "key": "alt+i",
        "command": "highlightUtils.goToHighlightedLocations",
        "args": {
            "at": 0,
            "goToMode": "goto"
        }
    }

@zardoy
Copy link
Owner Author

zardoy commented May 24, 2024

I also need this feature, it is not hard to implement but I never had time to do it 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low-priority Not in my personal plan/roadmap. Pr still welcome!
Projects
None yet
Development

No branches or pull requests

2 participants