Skip to content

Commit

Permalink
added config setting for quickfix length
Browse files Browse the repository at this point in the history
  • Loading branch information
nosami committed May 17, 2013
1 parent ca150f7 commit 0cbb004
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
3 changes: 3 additions & 0 deletions plugin/OmniSharp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ let g:OmniSharp_host = get(g:, 'OmniSharp_host', 'http://localhost:2000')
"Default value for the timeout value
let g:OmniSharp_timeout = get(g:, 'OmniSharp_timeout', 1)

"Default value for the timeout value
let g:OmniSharp_quickFixLength = get(g:, 'OmniSharp_quickFixLength', 60)

"Don't use the preview window by default
let g:OmniSharp_typeLookupInPreview = get(g:, 'OmniSharp_typeLookupInPreview', 0)

Expand Down
6 changes: 4 additions & 2 deletions python/OmniSharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def getCompletions(ret, column, partialWord):
logger.error(command)

def findUsages(ret):
js = getResponse('/findusages')

parameters = {}
parameters['MaxWidth'] = int(vim.eval('g:OmniSharp_quickFixLength'))
js = getResponse('/findusages', parameters)
if(js != ''):
usages = json.loads(js)['Usages']
populateQuickFix(ret, usages)
Expand Down Expand Up @@ -112,7 +115,6 @@ def findImplementations(ret):
def gotoDefinition():
js = getResponse('/gotodefinition');
if(js != ''):

definition = json.loads(js)
filename = definition['FileName']
if(filename != None):
Expand Down
2 changes: 2 additions & 0 deletions server/OmniSharp.Tests/Build/BuildLogParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public void Should_parse_syntax_error()
@"; expected");

}


[Test]
public void Should_parse_missing_file_error()
{
Expand Down
38 changes: 29 additions & 9 deletions server/OmniSharp/FindUsages/AstNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,41 @@ namespace OmniSharp.FindUsages
{
public static class AstNodeExtensions
{
public static string Preview(this AstNode node, CSharpFile file)
public static string Preview(this AstNode node, CSharpFile file, int maxWidth)
{
var location = node.StartLocation;
var offset = file.Document.GetOffset(location.Line, location.Column);
var line = file.Document.GetLineByNumber(location.Line);
if (line.Length < 50)
var startLocation = node.StartLocation;
var startOffset = file.Document.GetOffset(startLocation.Line, startLocation.Column);


var line = file.Document.GetLineByNumber(startLocation.Line);

var lineText = file.Document.GetText(line.Offset, line.Length);

if (line.Length < maxWidth)
{
return file.Document.GetText(line.Offset, line.Length);
// Don't truncate
return lineText;
}

var start = Math.Max(line.Offset, offset - 60);
var end = Math.Min(line.EndOffset, offset + 60);
var endLocation = node.EndLocation;
var endOffset = file.Document.GetOffset(endLocation.Line, endLocation.Column);

const string ellipsis = "...";

return "..." + file.Document.GetText(start, end - start).Trim() + "...";
var charactersEitherSide = (maxWidth - (ellipsis.Length * 2));

// Place the node text as close as possible to the centre of the returned text
var start = Math.Max(line.Offset, startOffset - charactersEitherSide);
var end = Math.Min(line.EndOffset, endOffset + charactersEitherSide);

return ellipsis + file.Document.GetText(start, end - start).Trim() + ellipsis;
}

public static AstNode GetDefinition(this AstNode node)
{
if (node is ConstructorInitializer)
return null;

if (node is ObjectCreateExpression)
node = ((ObjectCreateExpression)node).Type;

Expand All @@ -51,14 +66,19 @@ public static AstNode GetDefinition(this AstNode node)

if (node is ParameterDeclaration)
node = ((ParameterDeclaration)node).NameToken;

if (node is ConstructorDeclaration)
node = ((ConstructorDeclaration)node).NameToken;

if (node is DestructorDeclaration)
node = ((DestructorDeclaration)node).NameToken;

if (node is NamedArgumentExpression)
node = ((NamedArgumentExpression)node).NameToken;

if (node is NamedExpression)
node = ((NamedExpression)node).NameToken;

if (node is VariableInitializer)
node = ((VariableInitializer)node).NameToken;

Expand Down
2 changes: 1 addition & 1 deletion server/OmniSharp/FindUsages/FindUsagesHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public FindUsagesResponse FindUsages(FindUsagesRequest request)
var usages = result.Select(node => new QuickFix
{
FileName = node.GetRegion().FileName,
Text = node.Preview(_solution.GetFile(node.GetRegion().FileName)).Replace("'", "''"),
Text = node.Preview(_solution.GetFile(node.GetRegion().FileName), request.MaxWidth).Replace("'", "''"),
Line = node.StartLocation.Line,
Column = node.StartLocation.Column,
});
Expand Down
7 changes: 7 additions & 0 deletions server/OmniSharp/FindUsages/FindUsagesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@ namespace OmniSharp.FindUsages
{
public class FindUsagesRequest : Request
{
private int _maxWidth = 100;

public int MaxWidth
{
get { return _maxWidth; }
set { _maxWidth = value; }
}
}
}
15 changes: 3 additions & 12 deletions server/OmniSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ private static void Main(string[] args)
}

bool createdNew;
using (var mutex = new Mutex(true, "OmniSharp", out createdNew))
using (var mutex = new Mutex(true, "OmniSharp" + port, out createdNew))
{
if (createdNew)
{
StartServer(solutionPath, port);
}
else
{
Console.WriteLine("Detected an OmniSharp instance already loaded. Press a key.");
Console.WriteLine("Detected an OmniSharp instance already running on port " + port + ". Press a key.");
Console.ReadKey();
}
}
Expand All @@ -71,16 +71,7 @@ private static void StartServer(string solutionPath, int port)

var nancyHost = new NancyHost(new Bootstrapper(solution), new Uri("http://localhost:" + port));

try
{
nancyHost.Start();
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
//Quit gracefully
return;
}
nancyHost.Start();

while (Console.ReadLine() != "exit")
{
Expand Down

0 comments on commit 0cbb004

Please sign in to comment.