Skip to content

Commit

Permalink
Merge pull request #259 from OmniSharp/dnx-frameworks
Browse files Browse the repository at this point in the history
Add Dnx frameworks
  • Loading branch information
nosami committed Jul 8, 2015
2 parents 0ad9b17 + fc371d5 commit 6349b71
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ public async Task<HighlightResponse> Highlight(HighlightRequest request)
}
else
{
foreach (var line in request.Lines)
var linesToClassify = request.Lines.Join(
text.Lines,
line => line - 1,
line => line.LineNumber,
(requestLine, line) => line.Span);
foreach (var lineSpan in linesToClassify)
{
foreach (var span in await Classifier.GetClassifiedSpansAsync(document, text.Lines[line - 1].Span))
foreach (var span in await Classifier.GetClassifiedSpansAsync(document, lineSpan))
{
spans.Add(span);
}
Expand Down
14 changes: 7 additions & 7 deletions src/OmniSharp/Dnx/DnxProjectSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void Initalize()

var frameworkProject = project.ProjectsByFramework.GetOrAdd(frameworkData.FrameworkName, framework =>
{
return new FrameworkProject(project, framework);
return new FrameworkProject(project, frameworkData);
});

var id = frameworkProject.ProjectId;
Expand Down Expand Up @@ -233,7 +233,7 @@ public void Initalize()
var referencedFrameworkProject = referencedProject.ProjectsByFramework.GetOrAdd(projectReference.Framework.FrameworkName,
framework =>
{
return new FrameworkProject(referencedProject, framework);
return new FrameworkProject(referencedProject, projectReference.Framework);
});

var projectReferenceId = referencedFrameworkProject.ProjectId;
Expand Down Expand Up @@ -449,7 +449,7 @@ private void TriggerDependeees(string path, string messageType)
_context.Connection.Post(message);
}
}

private void WatchProject(string projectFile)
{
// Whenever the project file changes, trigger FilesChanged to the design time host
Expand Down Expand Up @@ -538,7 +538,7 @@ private bool ScanForProjects()
if (_context.TryAddProject(projectInThisFolder))
{
_logger.LogInformation(string.Format("Found project '{0}'.", projectInThisFolder));

anyProjects = true;
}
}
Expand All @@ -560,11 +560,11 @@ private bool ScanForProjects()
// The matcher works on CoreCLR but Omnisharp still targets aspnetcore50 instead of
// dnxcore50
paths = _directoryEnumerator.SafeEnumerateFiles(_env.Path, "project.json");
#endif
#endif
foreach (var path in paths)
{
string projectFile = null;

if (Path.GetFileName(path) == "project.json")
{
projectFile = path;
Expand Down Expand Up @@ -602,4 +602,4 @@ private static Task ConnectAsync(Socket socket, IPEndPoint endPoint)
return Task.Factory.FromAsync((cb, state) => socket.BeginConnect(endPoint, cb, state), ar => socket.EndConnect(ar), null);
}
}
}
}
13 changes: 10 additions & 3 deletions src/OmniSharp/Dnx/FrameworkProject.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using Microsoft.Framework.DesignTimeHost.Models.OutgoingMessages;

namespace OmniSharp.Dnx
{
Expand All @@ -10,6 +11,10 @@ public class FrameworkProject

public string Framework { get; private set; }

public string FriendlyName { get; private set; }

public string ShortName { get; private set; }

public Dictionary<string, DocumentId> Documents { get; set; }

public Dictionary<string, MetadataReference> FileReferences { get; set; }
Expand All @@ -26,10 +31,12 @@ public class FrameworkProject

public bool Loaded { get; set; }

public FrameworkProject(Project project, string framework)
public FrameworkProject(Project project, FrameworkData frameworkData)
{
Project = project;
Framework = framework;
Framework = frameworkData.FrameworkName;
FriendlyName = frameworkData.FriendlyName;
ShortName = frameworkData.ShortName;
ProjectId = ProjectId.CreateNewId();
Documents = new Dictionary<string, DocumentId>();
FileReferences = new Dictionary<string, MetadataReference>();
Expand All @@ -44,4 +51,4 @@ public override string ToString()
return Project.Name + "+" + Framework + " (" + Project.Path + ")";
}
}
}
}
21 changes: 21 additions & 0 deletions src/OmniSharp/Models/v1/DnxFramework.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.DesignTimeHost.Models.OutgoingMessages;
using OmniSharp.Dnx;

namespace OmniSharp.Models
{
public class DnxFramework
{
public string Name { get; set; }
public string FriendlyName { get; set; }
public string ShortName { get; set; }

public DnxFramework(FrameworkProject project)
{
Name = project.Framework;
FriendlyName = project.FriendlyName;
ShortName = project.ShortName;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Framework.DesignTimeHost.Models.OutgoingMessages;
using OmniSharp.Dnx;

namespace OmniSharp.Models
Expand All @@ -12,6 +13,7 @@ public class DnxProject
public IList<string> Configurations { get; set; }
public IList<string> ProjectSearchPaths { get; set; }
public IList<string> Frameworks { get; set; }
public IList<DnxFramework> DnxFrameworks { get; set; }
public string GlobalJsonPath { get; set; }
public IList<string> SourceFiles { get; set; }

Expand All @@ -24,6 +26,7 @@ public DnxProject(Project project)
GlobalJsonPath = project.GlobalJsonPath;
ProjectSearchPaths = project.ProjectSearchPaths;
Frameworks = project.ProjectsByFramework.Keys.ToList();
DnxFrameworks = project.ProjectsByFramework.Values.Select(framework => new DnxFramework(framework)).ToList();
SourceFiles = project.SourceFiles;
}
}
Expand Down
22 changes: 11 additions & 11 deletions tests/OmniSharp.Tests/GoToFileFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ public void ReturnsAListOfAllWorkspaceFiles()
{
var source1 = @"class Foo {}";
var source2 = @"class Bar {}";

var workspace = TestHelpers.CreateSimpleWorkspace(new Dictionary<string, string> {
{ "foo.cs", source1 }, { "bar.cs", source2}
});
var controller = new OmnisharpController(workspace, null);
var response = controller.GoToFile(new Request());
Assert.Equal(2, response.QuickFixes.Count());
Assert.Equal("foo.cs", response.QuickFixes.ElementAt(0).FileName);
Assert.Equal("bar.cs", response.QuickFixes.ElementAt(1).FileName);
}

Assert.Equal(2, response.QuickFixes.Count());
Assert.Equal("foo.cs", response.QuickFixes.ElementAt(0).FileName);
Assert.Equal("bar.cs", response.QuickFixes.ElementAt(1).FileName);
}

[Fact]
public void ReturnsEmptyResponseForEmptyWorskpace()
{
var workspace = TestHelpers.CreateSimpleWorkspace(new Dictionary<string, string>());
var controller = new OmnisharpController(workspace, null);
var response = controller.GoToFile(new Request());
Assert.Equal(0, response.QuickFixes.Count());
}

Assert.Equal(0, response.QuickFixes.Count());
}
}
}
}

0 comments on commit 6349b71

Please sign in to comment.