import { DefinitionLink , Range } from 'vscode-languageserver' ; import { Position , TextDocument } from 'vscode-languageserver-textdocument' ; import { Scalar } from 'yaml/types' ; import { DocsLibrary } from '../services/docsLibrary' ; import { toLspRange } from '../utils/misc' ; import { AncestryBuilder , getOrigRange , getPathAt , isTaskParam , parseAllDocuments , } from '../utils/yaml' ; export async function getDefinition ( document , position , docsLibrary ) { const yamlDocs = parseAllDocuments ( document . getText ( ) ) ; const path = getPathAt ( document , position , yamlDocs ) ; if ( path ) { const node = path [ path . length - 1 ] ; if ( node instanceof Scalar && new AncestryBuilder ( path ) . parentOfKey ( ) . get ( ) ) { if ( isTaskParam ( path ) ) { const [ module ] = await docsLibrary . findModule ( node . value , path , document . uri ) ; if ( module ) { const range = getOrigRange ( node ) ; return [ { targetUri : module . source , originSelectionRange : range ? toLspRange ( range , document ) : undefined , targetRange : Range . create ( module . sourceLineRange [ 0 ] , 0 , module . sourceLineRange [ 1 ] , 0 ) , targetSelectionRange : Range . create ( module . sourceLineRange [ 0 ] , 0 , module . sourceLineRange [ 1 ] , 0 ) , } , ] ; } } } } return null ; }