From 21bd90826a2a24c90ed9b3f08ae19e6215935972 Mon Sep 17 00:00:00 2001 From: Ivan Zlatev Date: Sat, 11 Feb 2017 14:11:28 +0000 Subject: [PATCH] Implemented "Go to Implementation". Closes #37 --- CHANGELOG.md | 17 ++++++++++----- package.json | 4 ++-- src/features/implementationProvider.ts | 30 ++++++++++++++++++++++++++ src/omnisharp/extension.ts | 2 ++ src/omnisharp/protocol.ts | 5 +++++ src/omnisharp/utils.ts | 4 ++++ 6 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/features/implementationProvider.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index cabea91d1a..941cfbcfbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ +## 1.8.0 _(Not Yet Released)_ + +### Code Actions + +* Support for "Go to Implementation" and "Peek Implementation". ([#37](https://github.com/OmniSharp/omnisharp-vscode/issues/37)) _(Contributed by [@ivanz](https://github.com/ivanz))_ + + ## 1.7.0 (February 8, 2017) -#### Syntax Hightlighting +### Syntax Hightlighting * Introduced a brand new TextMate grammar written from scratch that provides much more robust C# syntax highlighting. ([#101](https://github.com/OmniSharp/omnisharp-vscode/issues/101), [#225](https://github.com/OmniSharp/omnisharp-vscode/issues/225), [#268](https://github.com/OmniSharp/omnisharp-vscode/issues/268), [#316](https://github.com/OmniSharp/omnisharp-vscode/issues/316), [#674](https://github.com/OmniSharp/omnisharp-vscode/issues/674), [#706](https://github.com/OmniSharp/omnisharp-vscode/issues/706), [#731](https://github.com/OmniSharp/omnisharp-vscode/issues/731), [#746](https://github.com/OmniSharp/omnisharp-vscode/issues/746), [#782](https://github.com/OmniSharp/omnisharp-vscode/issues/782), [#802](https://github.com/OmniSharp/omnisharp-vscode/issues/802), [#816](https://github.com/OmniSharp/omnisharp-vscode/issues/816), [#829](https://github.com/OmniSharp/omnisharp-vscode/issues/829), [#830](https://github.com/OmniSharp/omnisharp-vscode/issues/830), [#861](https://github.com/OmniSharp/omnisharp-vscode/issues/861), [#1078](https://github.com/OmniSharp/omnisharp-vscode/issues/1078), [#1084](https://github.com/OmniSharp/omnisharp-vscode/issues/1084), [#1086](https://github.com/OmniSharp/omnisharp-vscode/issues/1086), [#1091](https://github.com/OmniSharp/omnisharp-vscode/issues/1091), [#1096](https://github.com/OmniSharp/omnisharp-vscode/issues/1096), [#1097](https://github.com/OmniSharp/omnisharp-vscode/issues/1097), [#1106](https://github.com/OmniSharp/omnisharp-vscode/issues/1106), [#1115](https://github.com/OmniSharp/omnisharp-vscode/issues/1108)) * The C# TextMate grammar has a new home! Issues and contributions are welcome at [https://github.com/dotnet/csharp-tmLanguage](https://github.com/dotnet/csharp-tmLanguage). @@ -83,7 +90,7 @@ * Brings support for running all supported distros on top of Linux Kernel >= 4.6 * Enable debugger support for Arch Linux ([#564](https://github.com/OmniSharp/omnisharp-vscode/issues/564)) * Improve debugger install errors for macOS without openSSL symlinks ([#986](https://github.com/OmniSharp/omnisharp-vscode/pull/986)), and x86 Windows ([#998](https://github.com/OmniSharp/omnisharp-vscode/pull/998)). -* Improve debugger performance using precompiled debugger binaries ([#896](https://github.com/OmniSharp/omnisharp-vscode/issues/896))([#971](https://github.com/OmniSharp/omnisharp-vscode/issues/971)). +* Improve debugger performance using precompiled debugger binaries ([#896](https://github.com/OmniSharp/omnisharp-vscode/issues/896))([#971](https://github.com/OmniSharp/omnisharp-vscode/issues/971)). #### Syntax Highlighting @@ -91,7 +98,7 @@ * Fix for field declarations. ([#757](https://github.com/OmniSharp/omnisharp-vscode/issues/757)) * Fix for generic types with multiple type parameters. ([#960](https://github.com/OmniSharp/omnisharp-vscode/issues/960)) * Proper support for interpolated strings (verbatim and non-verbatim). ([#852](https://github.com/OmniSharp/omnisharp-vscode/issues/852)) - * Fix for multi-line properties. ([#854](https://github.com/OmniSharp/omnisharp-vscode/issues/854)) + * Fix for multi-line properties. ([#854](https://github.com/OmniSharp/omnisharp-vscode/issues/854)) * Fixes for events, nested type references (e.g. `Root.IInterface`), variable declarations, nested classes, and fields spanning multiple lines #### Hover Tooltips @@ -117,7 +124,7 @@ * Ensure diagnostics are cleared in files when they are no longer needed. ([#858](https://github.com/OmniSharp/omnisharp-vscode/issues/858)) * Enqueue requests for diagnostics in visible editors when the extension starts up. ([#843](https://github.com/OmniSharp/omnisharp-vscode/issues/843)) * Provide fallback URLs for debugger downloads. ([#930](https://github.com/OmniSharp/omnisharp-vscode/issues/930)) -* Properly require .NET Framework 4.6 in the OmniSharp.exe.config file to ensure that the user is displayed a dialog on Windows machines that don't have .NET Framework 4.6 installed. ([#937](https://github.com/OmniSharp/omnisharp-vscode/issues/937)) +* Properly require .NET Framework 4.6 in the OmniSharp.exe.config file to ensure that the user is displayed a dialog on Windows machines that don't have .NET Framework 4.6 installed. ([#937](https://github.com/OmniSharp/omnisharp-vscode/issues/937)) * Fix issue with installing on non-English installations of Windows. ([#938](https://github.com/OmniSharp/omnisharp-vscode/issues/938)) * Display platform information when acquiring runtime dependencies. ([#948](https://github.com/OmniSharp/omnisharp-vscode/issues/948)) @@ -165,7 +172,7 @@ Several new settings have been added: #### Performance -* Major improvements have been made to editor performance. The communication with the OmniSharp server has been rewritten to allow long-running operations (such as gathering all errors and warnings) to queue while high priority operations (such as text buffer changes) run serially. ([#902](https://github.com/OmniSharp/omnisharp-vscode/pull/902)) _(Thanks to [@david-driscoll](https://github.com/david-driscoll) for his help with this change!)_ +* Major improvements have been made to editor performance. The communication with the OmniSharp server has been rewritten to allow long-running operations (such as gathering all errors and warnings) to queue while high priority operations (such as text buffer changes) run serially. ([#902](https://github.com/OmniSharp/omnisharp-vscode/pull/902)) _(Thanks to [@david-driscoll](https://github.com/david-driscoll) for his help with this change!)_ #### Other Improvements diff --git a/package.json b/package.json index c421b07a88..a13df276d3 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "tslint-microsoft-contrib": "^2.0.12", "typescript": "^2.0.3", "vsce": "^1.7.0", - "vscode": "^1.0.0" + "vscode": "^1.0.3" }, "runtimeDependencies": [ { @@ -300,7 +300,7 @@ } ], "engines": { - "vscode": "^1.5.0" + "vscode": "^1.9.0" }, "activationEvents": [ "onLanguage:csharp", diff --git a/src/features/implementationProvider.ts b/src/features/implementationProvider.ts new file mode 100644 index 0000000000..f51616f59a --- /dev/null +++ b/src/features/implementationProvider.ts @@ -0,0 +1,30 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import AbstractSupport from './abstractProvider'; +import { FindImplementationsRequest } from '../omnisharp/protocol'; +import * as serverUtils from '../omnisharp/utils'; +import { createRequest, toLocation } from '../omnisharp/typeConvertion'; +import { TextDocument, Position, CancellationToken, ImplementationProvider, ProviderResult, Definition } from 'vscode'; + +export default class CSharpImplementationProvider extends AbstractSupport implements ImplementationProvider { + constructor(server) { + super(server); + } + + public provideImplementation(document: TextDocument, position: Position, token: CancellationToken): ProviderResult { + const request = createRequest(document, position); + + return serverUtils.findImplementations(this._server, request, token).then(response => { + if (!response || !response.QuickFixes) { + return; + } + + return response.QuickFixes.map(fix => toLocation(fix)); + }); + } +} diff --git a/src/omnisharp/extension.ts b/src/omnisharp/extension.ts index 3c2deb33a2..7bd76385fb 100644 --- a/src/omnisharp/extension.ts +++ b/src/omnisharp/extension.ts @@ -7,6 +7,7 @@ import * as vscode from 'vscode'; import TelemetryReporter from 'vscode-extension-telemetry'; import DefinitionProvider from '../features/definitionProvider'; +import ImplementationProvider from '../features/implementationProvider'; import CodeLensProvider from '../features/codeLensProvider'; import DefinitionMetadataDocumentProvider from '../features/definitionMetadataDocumentProvider'; import DocumentHighlightProvider from '../features/documentHighlightProvider'; @@ -47,6 +48,7 @@ export function activate(context: vscode.ExtensionContext, reporter: TelemetryRe localDisposables.push(definitionMetadataDocumentProvider); localDisposables.push(vscode.languages.registerDefinitionProvider(documentSelector, new DefinitionProvider(server, definitionMetadataDocumentProvider))); + localDisposables.push(vscode.languages.registerImplementationProvider(documentSelector, new ImplementationProvider(server))); localDisposables.push(vscode.languages.registerCodeLensProvider(documentSelector, new CodeLensProvider(server))); localDisposables.push(vscode.languages.registerDocumentHighlightProvider(documentSelector, new DocumentHighlightProvider(server))); localDisposables.push(vscode.languages.registerDocumentSymbolProvider(documentSelector, new DocumentSymbolProvider(server))); diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index 4fb8865bfd..0e33cfe64c 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -21,6 +21,7 @@ export module Requests { export const FormatRange = '/formatRange'; export const GetCodeActions = '/getcodeactions'; export const GoToDefinition = '/gotoDefinition'; + export const FindImplementations = '/findimplementations'; export const Projects = '/projects'; export const RemoveFromProject = '/removefromproject'; export const Rename = '/rename'; @@ -70,6 +71,10 @@ export interface GoToDefinitionRequest extends Request WantMetadata?: boolean; } +export interface FindImplementationsRequest extends Request +{ +} + export interface LinePositionSpanTextChange { NewText: string; StartLine: number; diff --git a/src/omnisharp/utils.ts b/src/omnisharp/utils.ts index 9470154fba..3506ce7694 100644 --- a/src/omnisharp/utils.ts +++ b/src/omnisharp/utils.ts @@ -25,6 +25,10 @@ export function filesChanged(server: OmniSharpServer, requests: protocol.Request return server.makeRequest(protocol.Requests.FilesChanged, requests); } +export function findImplementations(server: OmniSharpServer, request: protocol.FindImplementationsRequest, token: vscode.CancellationToken) { + return server.makeRequest(protocol.Requests.FindImplementations, request); +} + export function findSymbols(server: OmniSharpServer, request: protocol.FindSymbolsRequest, token: vscode.CancellationToken) { return server.makeRequest(protocol.Requests.FindSymbols, request, token); }