diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index f36dba8ef..2940f63cb 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -7,26 +7,25 @@ import AbstractSupport from './abstractProvider'; import * as protocol from '../omnisharp/protocol'; import * as serverUtils from '../omnisharp/utils'; import { createRequest } from '../omnisharp/typeConversion'; -import { HoverProvider, Hover, TextDocument, CancellationToken, Position } from 'vscode'; -import { GetDocumentationString } from './documentation'; +import { HoverProvider, Hover, TextDocument, CancellationToken, Position, MarkdownString } from 'vscode'; export default class OmniSharpHoverProvider extends AbstractSupport implements HoverProvider { public async provideHover(document: TextDocument, position: Position, token: CancellationToken): Promise { - - let req = createRequest(document, position); - req.IncludeDocumentation = true; - + let request = createRequest(document, position); try { - let value = await serverUtils.typeLookup(this._server, req, token); - if (value && value.Type) { - let documentation = GetDocumentationString(value.StructuredDocumentation); - let contents = [{ language: 'csharp', value: value.Type }, documentation]; - return new Hover(contents); + const response = await serverUtils.getQuickInfo(this._server, request, token); + if (!response || !response.Markdown) { + return undefined; } + + const markdownString = new MarkdownString; + markdownString.appendMarkdown(response.Markdown); + + return new Hover(markdownString); } catch (error) { - return undefined; //No hover result could be obtained + return undefined; } } -} \ No newline at end of file +} diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index dcf681d0e..d6cdd6e6d 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -29,6 +29,7 @@ export module Requests { export const UpdateBuffer = '/updatebuffer'; export const Metadata = '/metadata'; export const ReAnalyze = '/reanalyze'; + export const QuickInfo = '/quickinfo'; } export namespace WireProtocol { @@ -473,6 +474,13 @@ export enum FileChangeType { DirectoryDelete = "DirectoryDelete" } +export interface QuickInfoRequest extends Request { +} + +export interface QuickInfoResponse { + Markdown?: string; +} + export namespace V2 { export module Requests { diff --git a/src/omnisharp/utils.ts b/src/omnisharp/utils.ts index aed19836c..c5d3bad52 100644 --- a/src/omnisharp/utils.ts +++ b/src/omnisharp/utils.ts @@ -9,6 +9,7 @@ import * as path from 'path'; import * as protocol from './protocol'; import * as vscode from 'vscode'; import { MSBuildProject } from './protocol'; +import { CancellationToken } from 'vscode-languageserver-protocol'; export async function autoComplete(server: OmniSharpServer, request: protocol.AutoCompleteRequest, token: vscode.CancellationToken) { return server.makeRequest(protocol.Requests.AutoComplete, request, token); @@ -168,6 +169,10 @@ export async function getSemanticHighlights(server: OmniSharpServer, request: pr return server.makeRequest(protocol.V2.Requests.Highlight, request); } +export async function getQuickInfo(server: OmniSharpServer, request: protocol.QuickInfoRequest, token: CancellationToken) { + return server.makeRequest(protocol.Requests.QuickInfo, request, token); +} + export async function isNetCoreProject(project: protocol.MSBuildProject) { return project.TargetFrameworks.find(tf => tf.ShortName.startsWith('netcoreapp') || tf.ShortName.startsWith('netstandard')) !== undefined; } diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts index dd6e342fc..d6c0e8588 100644 --- a/test/integrationTests/hoverProvider.integration.test.ts +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -10,6 +10,8 @@ import { should, expect } from 'chai'; import { activateCSharpExtension, isRazorWorkspace } from './integrationHelpers'; import testAssetWorkspace from './testAssets/testAssetWorkspace'; +export type Test = 'a' | 'b' | ['c', any]; + const chai = require('chai'); chai.use(require('chai-arrays')); chai.use(require('chai-fs')); @@ -40,8 +42,8 @@ suite(`Hover Provider: ${testAssetWorkspace.description}`, function () { await vscode.commands.executeCommand("vscode.open", fileUri); let c = (await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri, new vscode.Position(10, 29))); let answer: string = - `Checks if object is tagged with the tag.`; + "```csharp\nbool testissue.Compare(int gameObject, string tagName)\n```\n\nChecks if object is tagged with the tag\\.\n\nReturns:\n\n Returns true if object is tagged with tag\\."; - expect((<{ language: string; value: string }>c[0].contents[1]).value).to.equal(answer); + expect((<{ language: string; value: string }>c[0].contents[0]).value).to.equal(answer); }); -}); \ No newline at end of file +});