Skip to content

Commit

Permalink
Move omnisharp vscode to the new hover implementation
Browse files Browse the repository at this point in the history
Hover implemention is in PR here: OmniSharp/omnisharp-roslyn#1860.
  • Loading branch information
333fred committed Jul 24, 2020
1 parent cb9dfa3 commit 913df57
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/features/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,44 @@ 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<Hover> {
let request = createRequest<protocol.V2.QuickInfoRequest>(document, position);
try {
const response = await serverUtils.getQuickInfo(this._server, request, token);
if (!response.Description && !response.RemainingSections && !response.Summary) {
return undefined;
}

let req = createRequest<protocol.TypeLookupRequest>(document, position);
req.IncludeDocumentation = true;
let markdownString = new MarkdownString;
const language = "csharp";
if (response.Description) {
markdownString.appendCodeblock(response.Description, language);
}

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);
if (response.Summary) {
markdownString.appendMarkdown(response.Summary);
}

if (response.RemainingSections) {
for (const section of response.RemainingSections) {
if (section.IsCSharpCode) {
markdownString.appendCodeblock(section.Text, language);
}
else {
markdownString.appendText("\n");
markdownString.appendMarkdown(section.Text);
}
}
}

return new Hover(markdownString);
}
catch (error) {
return undefined; //No hover result could be obtained
return undefined;
}
}
}
}
15 changes: 15 additions & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ export namespace V2 {
export const BlockStructure = '/v2/blockstructure';
export const CodeStructure = '/v2/codestructure';
export const Highlight = '/v2/highlight';
export const QuickInfo = '/v2/quickinfo';
}

export interface SemanticHighlightSpan {
Expand Down Expand Up @@ -711,6 +712,20 @@ export namespace V2 {
Kind: string;
}

export interface QuickInfoRequest extends Request {
}

export interface QuickInfoResponse {
Description?: string;
Summary?: string;
RemainingSections?: QuickInfoResponseSection[];
}

export interface QuickInfoResponseSection {
IsCSharpCode: boolean;
Text: string;
}

export module SymbolKinds {
// types
export const Class = 'class';
Expand Down
5 changes: 5 additions & 0 deletions src/omnisharp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.AutoCompleteResponse[]>(protocol.Requests.AutoComplete, request, token);
Expand Down Expand Up @@ -168,6 +169,10 @@ export async function getSemanticHighlights(server: OmniSharpServer, request: pr
return server.makeRequest<protocol.V2.SemanticHighlightResponse>(protocol.V2.Requests.Highlight, request);
}

export async function getQuickInfo(server: OmniSharpServer, request: protocol.V2.QuickInfoRequest, token: CancellationToken) {
return server.makeRequest<protocol.V2.QuickInfoResponse>(protocol.V2.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;
}
Expand Down

0 comments on commit 913df57

Please sign in to comment.