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

fix: get source text exeptions #2656

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -56,8 +57,17 @@ public async Task<InlayHintResponse> Handle(InlayHintRequest request)
return InlayHintResponse.None;
}

var sourceText = await document.GetTextAsync();
var mappedSpan = sourceText.GetSpanFromRange(request.Location.Range);
SourceText sourceText;
TextSpan mappedSpan;
try
{
sourceText = await document.GetTextAsync();
mappedSpan = sourceText.GetSpanFromRange(request.Location.Range);
}
catch (ArgumentOutOfRangeException)
{
return InlayHintResponse.None;
}

var inlayHintsOptions = _omniSharpOptions.CurrentValue.RoslynExtensionsOptions.InlayHintsOptions;
var options = new OmniSharpInlineHintsOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.Extensions;
using OmniSharp.Mef;
using OmniSharp.Models;
Expand Down Expand Up @@ -103,8 +105,17 @@ throughExpression is LiteralExpressionSyntax ||

private async Task<InvocationContext> GetInvocation(Document document, Request request)
{
var sourceText = await document.GetTextAsync();
var position = sourceText.GetTextPosition(request);
SourceText sourceText;
int position;
try
{
sourceText = await document.GetTextAsync();
position = sourceText.GetTextPosition(request);
}
catch (ArgumentOutOfRangeException)
{
return null;
}
var tree = await document.GetSyntaxTreeAsync();
var root = await tree.GetRootAsync();
var node = root.FindToken(position).Parent;
Expand Down
Loading