(session: Session, params: lsp.HoverParams)
| 17 | const scssLS = getSCSSLanguageService(); |
| 18 | |
| 19 | export function onHover(session: Session, params: lsp.HoverParams): lsp.Hover | null { |
| 20 | const lsInfo = session.getLSAndScriptInfo(params.textDocument); |
| 21 | if (lsInfo === null) { |
| 22 | return null; |
| 23 | } |
| 24 | const {languageService, scriptInfo} = lsInfo; |
| 25 | const offset = lspPositionToTsPosition(scriptInfo, params.position); |
| 26 | const info = languageService.getQuickInfoAtPosition(scriptInfo.fileName, offset); |
| 27 | if (!info) { |
| 28 | const sf = session.getDefaultProjectForScriptInfo(scriptInfo)?.getSourceFile(scriptInfo.path); |
| 29 | if (!sf) { |
| 30 | return null; |
| 31 | } |
| 32 | const node = getTokenAtPosition(sf, offset); |
| 33 | if (!isInlineStyleNode(node)) { |
| 34 | return null; |
| 35 | } |
| 36 | const virtualScssDocContents = getSCSSVirtualContent(sf); |
| 37 | const virtualScssDoc = TextDocument.create( |
| 38 | params.textDocument.uri.toString(), |
| 39 | 'scss', |
| 40 | 0, |
| 41 | virtualScssDocContents, |
| 42 | ); |
| 43 | const stylesheet = scssLS.parseStylesheet(virtualScssDoc); |
| 44 | return scssLS.doHover(virtualScssDoc, params.position, stylesheet); |
| 45 | } |
| 46 | const {kind, kindModifiers, textSpan, displayParts, documentation, tags} = info; |
| 47 | let desc = kindModifiers ? kindModifiers + ' ' : ''; |
| 48 | if (displayParts && displayParts.length > 0) { |
| 49 | // displayParts does not contain info about kindModifiers |
| 50 | // but displayParts does contain info about kind |
| 51 | desc += displayParts.map((dp) => dp.text).join(''); |
| 52 | } else { |
| 53 | desc += kind; |
| 54 | } |
| 55 | const contents: lsp.MarkedString[] = [ |
| 56 | { |
| 57 | language: 'typescript', |
| 58 | value: desc, |
| 59 | }, |
| 60 | ]; |
| 61 | const mds = documentationToMarkdown( |
| 62 | documentation, |
| 63 | tags, |
| 64 | (fileName: string) => session.getLSAndScriptInfo(fileName)?.scriptInfo, |
| 65 | ); |
| 66 | contents.push(mds.join('\n')); |
| 67 | return { |
| 68 | contents, |
| 69 | range: tsTextSpanToLspRange(scriptInfo, textSpan), |
| 70 | }; |
| 71 | } |
no test coverage detected