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

Move omnisharp vscode to the new hover implementation #3928

Merged
merged 7 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/features/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Hover> {

let req = createRequest<protocol.TypeLookupRequest>(document, position);
req.IncludeDocumentation = true;

let request = createRequest<protocol.QuickInfoRequest>(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;
}
}
}
}
8 changes: 8 additions & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
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.QuickInfoRequest, token: CancellationToken) {
return server.makeRequest<protocol.QuickInfoResponse>(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;
}
Expand Down
8 changes: 5 additions & 3 deletions test/integrationTests/hoverProvider.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -40,8 +42,8 @@ suite(`Hover Provider: ${testAssetWorkspace.description}`, function () {
await vscode.commands.executeCommand("vscode.open", fileUri);
let c = <vscode.Hover[]>(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);
});
});
});