├── .gitignore
├── .gitmodules
├── .nuget
├── NuGet.Config
├── NuGet.exe
└── NuGet.targets
├── .travis.yml
├── LICENSE.md
├── Microsoft.Build.Evaluation
├── Microsoft.Build.Evaluation.csproj
├── Project.cs
├── ProjectItem.cs
└── Properties
│ └── AssemblyInfo.cs
├── OmniSharp.Tests
├── AutoComplete
│ ├── BugFixTests.cs
│ ├── CompletionTestBase.cs
│ ├── CompletionsSpecBase.cs
│ ├── ConstructorParameterCompletions.cs
│ ├── DerivedTypeCompletions.cs
│ ├── GenericCompletions.cs
│ ├── IntegrationTest.cs
│ ├── MethodHeaderTests.cs
│ ├── NamespaceCompletions.cs
│ ├── SnippetGenerationTests.cs
│ └── SnippetTests.cs
├── Build
│ └── BuildLogParserTests.cs
├── CodeFormat
│ └── CodeFormatTest.cs
├── FakeAssembly.cs
├── FakeFileSystem.cs
├── FakeProject.cs
├── FakeSolution.cs
├── FindUsages
│ └── IntegrationTest.cs
├── FixUsings
│ └── FixUsingsTests.cs
├── GoToImplementation
│ └── GoToImplementation.cs
├── OmniSharp.Tests.csproj
├── Overrides
│ └── TestOverrideContext.cs
├── ProjectManipulation
│ ├── AddReference
│ │ ├── AddFileReferenceTests.cs
│ │ ├── AddGacReferenceTests.cs
│ │ ├── AddProjectReferenceTests.cs
│ │ ├── AddReferenceTestsBase.cs
│ │ ├── AddToProjectProcessoryFactoryTests.cs
│ │ └── MockProject.cs
│ ├── AddToProject
│ │ └── AddToProjectTests.cs
│ └── RemoveFromProject
│ │ └── RemoveFromProjectTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── Rename
│ ├── Buffer.cs
│ ├── FakeSolutionBuilder.cs
│ ├── MultiFileRenameTests.cs
│ └── SimpleRenameTests.cs
├── SemanticErrors
│ └── SemanticErrors.cs
├── ShouldExtensions.cs
├── Solution
│ ├── SolutionTest.cs
│ └── minimal
│ │ ├── minimal.sln
│ │ └── minimal
│ │ ├── MyClass.cs
│ │ ├── MyClassContainer.cs
│ │ └── minimal.csproj
├── TestHelpers.cs
├── TypeLookup
│ ├── EmptyResults.cs
│ ├── IntegrationTest.cs
│ ├── LocalVariables.cs
│ ├── MemberVariables.cs
│ ├── Methods.cs
│ ├── Properties.cs
│ └── StringExtensions.cs
├── UnitTesting
│ ├── ContextInformationTests.cs
│ └── UnitTesting.cs
└── packages.config
├── OmniSharp.sln
├── OmniSharp
├── AutoComplete
│ ├── AutoCompleteHandler.cs
│ ├── AutoCompleteModule.cs
│ ├── AutoCompleteRequest.cs
│ ├── AutoCompleteResponse.cs
│ ├── BufferContext.cs
│ ├── CompletionData.cs
│ ├── CompletionDataExtensions.cs
│ ├── CompletionDataFactory.cs
│ ├── HelpExtension.cs
│ ├── HelpService.cs
│ ├── Metadata
│ │ ├── AutoCompleteMetadataModule.cs
│ │ ├── AutoCompleteRequestMetadataProvider.cs
│ │ └── AutoCompleteResponseMetadataProvider.cs
│ ├── MyCompletionCategory.cs
│ ├── ReturnTypeAmbience.cs
│ ├── SnippetGenerator.cs
│ └── StringExtensions.cs
├── Bootstrapper.cs
├── Build
│ ├── BuildCommandBuilder.cs
│ ├── BuildCommandModule.cs
│ ├── BuildHandler.cs
│ ├── BuildLogParser.cs
│ ├── BuildModule.cs
│ ├── BuildResponse.cs
│ ├── BuildTargetRequest.cs
│ ├── BuildTargetResponse.cs
│ └── Metadata
│ │ └── BuildCommandMetadataModule.cs
├── CheckAliveStatus
│ ├── CheckAliveStatusModule.cs
│ └── Metadata
│ │ └── CheckAliveStatusMetadataModule.cs
├── CheckReadyStatus
│ ├── CheckReadyStatusModule.cs
│ └── Metadata
│ │ └── CheckReadyStatusMetadataModule.cs
├── CodeActions
│ ├── CodeActionProviders.cs
│ ├── FixUsingsHandler.cs
│ ├── FixUsingsModule.cs
│ ├── FixUsingsResponse.cs
│ ├── GetCodeActionRequest.cs
│ ├── GetCodeActionsHandler.cs
│ ├── GetCodeActionsModule.cs
│ ├── GetCodeActionsResponse.cs
│ ├── Metadata
│ │ ├── FixUsingsMetadataModule.cs
│ │ ├── GetCodeActionsMetadataModule.cs
│ │ └── RunCodeActionMetadataModule.cs
│ ├── RunCodeActionModule.cs
│ ├── RunCodeActionRequest.cs
│ └── RunCodeActionsResponse.cs
├── CodeFormat
│ ├── CodeFormatHandler.cs
│ ├── CodeFormatModule.cs
│ ├── CodeFormatRequest.cs
│ ├── CodeFormatResponse.cs
│ └── Metadata
│ │ └── CodeFormatMetadataModule.cs
├── CodeIssues
│ ├── CodeIssueProviders.cs
│ ├── CodeIssuesHandler.cs
│ ├── CodeIssuesModule.cs
│ ├── GetCodeIssuesResponse.cs
│ ├── Metadata
│ │ └── CodeIssuesMetadataModule.cs
│ └── RunCodeIssuesResponse.cs
├── Common
│ ├── CygPathWrapper.cs
│ ├── Error.cs
│ ├── FileSystem.cs
│ ├── IFileSystem.cs
│ ├── Metadata
│ │ ├── QuickFixMetadataProvider.cs
│ │ ├── QuickFixResponseMetadataProvider.cs
│ │ └── RequestMetadataProvider.cs
│ ├── QuickFix.cs
│ ├── QuickFixResponse.cs
│ └── Request.cs
├── Configuration
│ ├── OmniSharpConfiguration.cs
│ ├── PathMode.cs
│ ├── PathReplacement.cs
│ └── TestCommands.cs
├── CurrentFileMembers
│ ├── CurrentFileMembersAsFlatModule.cs
│ ├── CurrentFileMembersAsTreeModule.cs
│ ├── CurrentFileMembersAsTreeResponse.cs
│ ├── CurrentFileMembersHandler.cs
│ ├── CurrentFileMembersRequest.cs
│ ├── CurrentFileTopLevelTypesModule.cs
│ ├── Metadata
│ │ ├── CurrentFileMembersAsFlatMetadataModule.cs
│ │ ├── CurrentFileMembersAsTreeMetadataModule.cs
│ │ └── CurrentFileTopLevelTypesMetadataModule.cs
│ └── Node.cs
├── Documentation
│ ├── DocumentationConverter.cs
│ ├── DocumentationFetcher.cs
│ ├── MonoDocDocumentationProvider.cs
│ └── XmlDocumentationProviderFactory.cs
├── Extensions
│ └── NodeExtensions.cs
├── FindProjects
│ ├── FindProjectsHandler.cs
│ ├── FindProjectsModule.cs
│ ├── FindProjectsResponse.cs
│ ├── MsBuildProject.cs
│ └── MsBuildWorkspaceInformation.cs
├── FindSymbols
│ ├── FindSymbolsHandler.cs
│ ├── FindSymbolsModule.cs
│ └── Metadata
│ │ └── FindSymbolsMetadataModule.cs
├── FindTypes
│ ├── FindTypesHandler.cs
│ ├── FindTypesModule.cs
│ └── Metadata
│ │ └── FindTypesMetadataModule.cs
├── FindUsages
│ ├── AstNodeExtensions.cs
│ ├── FindUsagesHandler.cs
│ ├── FindUsagesModule.cs
│ ├── FindUsagesRequest.cs
│ ├── MemberCollector.cs
│ └── Metadata
│ │ └── FindUsagesMetadataModule.cs
├── GotoDefinition
│ ├── GotoDefinitionHandler.cs
│ ├── GotoDefinitionModule.cs
│ ├── GotoDefinitionRequest.cs
│ ├── GotoDefinitionResponse.cs
│ └── Metadata
│ │ ├── GotoDefinitionMetadataModule.cs
│ │ ├── GotoDefinitionRequestMetadataProvider.cs
│ │ └── GotoDefinitionResponseMetadataProvider.cs
├── GotoFile
│ ├── GotoFileHandler.cs
│ ├── GotoFileModule.cs
│ └── Metadata
│ │ └── GotoFileMetadataModule.cs
├── GotoImplementation
│ ├── GotoImplementationHandler.cs
│ ├── GotoImplementationModule.cs
│ ├── GotoImplementationRequest.cs
│ ├── Location.cs
│ └── Metadata
│ │ └── GotoImplementationMetadataModule.cs
├── GotoRegion
│ ├── GetDirectivesAstVisitor.cs
│ ├── GotoRegionHandler.cs
│ ├── GotoRegionModule.cs
│ └── Metadata
│ │ └── GotoRegionMetadataModule.cs
├── Logger.cs
├── LookupAllTypes
│ ├── LookupAllTypesHandler.cs
│ ├── LookupAllTypesModule.cs
│ ├── LookupAllTypesRequest.cs
│ ├── LookupAllTypesResponse.cs
│ └── Metadata
│ │ └── LookupAllTypesMetadataModule.cs
├── OmniSharp.csproj
├── Options.cs
├── Overrides
│ ├── GetOverrideTargetsModule.cs
│ ├── GetOverrideTargetsResponse.cs
│ ├── Metadata
│ │ ├── GetOverrideTargetsMetadataModule.cs
│ │ └── RunOverrideTargetMetadataModule.cs
│ ├── OverrideContext.cs
│ ├── OverrideHandler.cs
│ ├── RunOverrideTargetModule.cs
│ ├── RunOverrideTargetRequest.cs
│ └── RunOverrideTargetResponse.cs
├── Parser
│ ├── BufferParser.cs
│ └── ParsedResult.cs
├── Platform.cs
├── PlatformHelper.cs
├── ProcessExtensions.cs
├── Program.cs
├── ProjectManipulation
│ ├── AddReference
│ │ ├── AddFileReferenceProcessor.cs
│ │ ├── AddGacReferenceProcessor.cs
│ │ ├── AddProjectReferenceProcessor.cs
│ │ ├── AddReferenceHandler.cs
│ │ ├── AddReferenceModule.cs
│ │ ├── AddReferenceProcessorFactory.cs
│ │ ├── AddReferenceRequest.cs
│ │ ├── AddReferenceResponse.cs
│ │ ├── IReferenceProcessor.cs
│ │ ├── Metadata
│ │ │ └── AddReferenceMetadataModule.cs
│ │ └── ReferenceProcessorBase.cs
│ ├── AddToProject
│ │ ├── AddToProjectHandler.cs
│ │ ├── AddToProjectModule.cs
│ │ ├── AddToProjectRequest.cs
│ │ └── Metadata
│ │ │ └── AddToProjectMetadataModule.cs
│ ├── ProjectNotFoundException.cs
│ └── RemoveFromProject
│ │ ├── Metadata
│ │ └── RemoveFromProjectMetadataModule.cs
│ │ ├── RemoveFromProjectHandler.cs
│ │ ├── RemoveFromProjectModule.cs
│ │ ├── RemoveFromProjectRequest.cs
│ │ └── XDocumentExtensions.cs
├── Properties
│ └── AssemblyInfo.cs
├── Refactoring
│ ├── OmniSharpRefactoringContext.cs
│ └── OmniSharpScript.cs
├── ReloadSolution
│ ├── Metadata
│ │ └── ReloadSolutionMetadataModule.cs
│ └── ReloadSolutionModule.cs
├── Rename
│ ├── Metadata
│ │ └── RenameMetadataModule.cs
│ ├── ModifiedFileResponse.cs
│ ├── RenameHandler.cs
│ ├── RenameModule.cs
│ ├── RenameRequest.cs
│ └── RenameResponse.cs
├── SemanticErrors
│ ├── Metadata
│ │ └── SemanticErrorsMetadataModule.cs
│ ├── SemanticErrorsHandler.cs
│ ├── SemanticErrorsModule.cs
│ └── SemanticErrorsResponse.cs
├── Solution
│ ├── AssemblySearch.cs
│ ├── CSharpFile.cs
│ ├── CSharpFolder.cs
│ ├── CSharpProject.cs
│ ├── CSharpSolution.cs
│ ├── Fusion.cs
│ ├── GacInterop.cs
│ ├── IProject.cs
│ ├── OrphanProject.cs
│ ├── Project.cs
│ ├── ProjectFinder.cs
│ ├── ProjectReference.cs
│ ├── SolutionPicker.cs
│ └── StringExtensions.cs
├── StopServer
│ ├── Metadata
│ │ └── StopServerMetadataModule.cs
│ └── StopServerModule.cs
├── SyntaxErrors
│ ├── CodeCheckHandler.cs
│ ├── CodeCheckModule.cs
│ ├── Metadata
│ │ ├── CodeCheckMetadataModule.cs
│ │ └── SyntaxErrorsMetadataModule.cs
│ ├── SyntaxErrorsHandler.cs
│ ├── SyntaxErrorsModule.cs
│ └── SyntaxErrorsResponse.cs
├── TestContextInformation
│ ├── GetContextResponse.cs
│ ├── GetTestContextHandler.cs
│ ├── GetTestContextModule.cs
│ ├── GetTestContextResponse.cs
│ └── TestCommandRequest.cs
├── TypeLookup
│ ├── Metadata
│ │ └── TypeLookupMetadataModule.cs
│ ├── TypeLookupHandler.cs
│ ├── TypeLookupModule.cs
│ ├── TypeLookupRequest.cs
│ └── TypeLookupResponse.cs
├── UpdateBuffer
│ ├── Metadata
│ │ └── UpdateBufferMetadataModule.cs
│ └── UpdateBufferModule.cs
├── app.config
├── config.json
└── packages.config
├── README.md
├── omnisharp.sublime-project
└── packages
├── CsQuery.1.3.4
├── CsQuery.1.3.4.nupkg
└── lib
│ └── net40
│ ├── CsQuery.XML
│ └── CsQuery.dll
├── NUnit.2.6.3
├── NUnit.2.6.3.nupkg
├── lib
│ ├── nunit.framework.dll
│ └── nunit.framework.xml
└── license.txt
├── Nancy.0.23.2
├── Nancy.0.23.2.nupkg
└── lib
│ └── net40
│ ├── Nancy.dll
│ └── Nancy.xml
├── Nancy.Authentication.Forms.0.23.2
├── Nancy.Authentication.Forms.0.23.2.nupkg
└── lib
│ └── net40
│ ├── Nancy.Authentication.Forms.XML
│ └── Nancy.Authentication.Forms.dll
├── Nancy.Hosting.Self.0.23.2
├── Nancy.Hosting.Self.0.23.2.nupkg
└── lib
│ └── net40
│ ├── Nancy.Hosting.Self.dll
│ └── Nancy.Hosting.Self.xml
├── Nancy.MetaData.0.23.2
├── Nancy.MetaData.0.23.2.nupkg
└── lib
│ └── net40
│ ├── Nancy.Metadata.Module.XML
│ └── Nancy.Metadata.Module.dll
├── Nancy.Swagger.0.1.0-alpha3
├── Nancy.Swagger.0.1.0-alpha3.nupkg
└── lib
│ └── net40
│ ├── Nancy.Swagger.XML
│ └── Nancy.Swagger.dll
├── Nancy.Testing.0.23.2
├── Nancy.Testing.0.23.2.nupkg
└── lib
│ └── net40
│ ├── Nancy.Testing.dll
│ └── Nancy.Testing.xml
├── Should.1.1.20
├── Should.1.1.20.nupkg
└── lib
│ └── Should.dll
├── Swagger.ObjectModel.0.1.0-alpha3
├── Swagger.ObjectModel.0.1.0-alpha3.nupkg
└── lib
│ └── net40
│ └── Swagger.ObjectModel.dll
├── System.IO.Abstractions.1.4.0.92
├── System.IO.Abstractions.1.4.0.92.nupkg
└── lib
│ └── net35
│ └── System.IO.Abstractions.dll
├── System.IO.Abstractions.TestingHelpers.1.4.0.92
├── System.IO.Abstractions.TestingHelpers.1.4.0.92.nupkg
└── lib
│ └── net35
│ └── System.IO.Abstractions.TestingHelpers.dll
├── monodoc.dll
└── repositories.config
/.gitignore:
--------------------------------------------------------------------------------
1 | *.sw*
2 | *.orig
3 | **/tags
4 | ## Ignore Visual Studio temporary files, build results, and
5 | ## files generated by popular Visual Studio add-ons.
6 |
7 | # User-specific files
8 | *.suo
9 | *.user
10 | *.sln.docstates
11 | *.sublime-workspace
12 | *.userprefs
13 |
14 | */test-results/
15 | # Build results
16 |
17 | [Dd]ebug*/
18 | [Rr]elease/
19 |
20 | #build/
21 |
22 |
23 | [Tt]est[Rr]esult
24 | [Bb]uild[Ll]og.*
25 |
26 | *_i.c
27 | *_p.c
28 | *.ilk
29 | *.meta
30 | *.obj
31 | *.pch
32 | *.pdb
33 | *.pgc
34 | *.pgd
35 | *.rsp
36 | *.sbr
37 | *.tlb
38 | *.tli
39 | *.tlh
40 | *.tmp
41 | *.vspscc
42 | *.vssscc
43 | .builds
44 | .DS_Store
45 |
46 | *.pidb
47 |
48 | *.log
49 | *.scc
50 | # Visual C++ cache files
51 | ipch/
52 | *.aps
53 | *.ncb
54 | *.opensdf
55 | *.sdf
56 |
57 | # Visual Studio profiler
58 | *.psess
59 | *.vsp
60 |
61 | # Guidance Automation Toolkit
62 | *.gpState
63 |
64 | # ReSharper is a .NET coding add-in
65 | _ReSharper*/
66 |
67 | *.[Rr]e[Ss]harper
68 |
69 | # NCrunch
70 | *.ncrunch*
71 | .*crunch*.local.xml
72 |
73 | # Installshield output folder
74 | [Ee]xpress
75 |
76 | # DocProject is a documentation generator add-in
77 | DocProject/buildhelp/
78 | DocProject/Help/*.HxT
79 | DocProject/Help/*.HxC
80 | DocProject/Help/*.hhc
81 | DocProject/Help/*.hhk
82 | DocProject/Help/*.hhp
83 | DocProject/Help/Html2
84 | DocProject/Help/html
85 |
86 | # Click-Once directory
87 | publish
88 |
89 | # Publish Web Output
90 | *.Publish.xml
91 |
92 | # Others
93 | [Bb]in
94 | [Oo]bj
95 | sql
96 | TestResults
97 | [Tt]est[Rr]esult*
98 | *.Cache
99 | ClientBin
100 | [Ss]tyle[Cc]op.*
101 | ~$*
102 | *.dbmdl
103 |
104 | *.[Pp]ublish.xml
105 |
106 | Generated_Code #added for RIA/Silverlight projects
107 |
108 | # Backup & report files from converting an old project file to a newer
109 | # Visual Studio version. Backup files are not needed, because we have git ;-)
110 | _UpgradeReport_Files/
111 | Backup*/
112 | UpgradeLog*.XML
113 |
114 | # NuGet
115 | packages/
116 |
117 | .projectile
118 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "NRefactory"]
2 | path = NRefactory
3 | url = https://github.com/icsharpcode/NRefactory.git
4 | [submodule "cecil"]
5 | path = cecil
6 | url = https://github.com/jbevain/cecil.git
7 |
--------------------------------------------------------------------------------
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: objective-c
2 |
3 | env:
4 | global:
5 | - EnableNuGetPackageRestore=true
6 | matrix:
7 | - MONO_VER="3.0.12"
8 |
9 | before_install:
10 | - wget "http://download.mono-project.com/archive/${MONO_VER}/macos-10-x86/MonoFramework-MDK-${MONO_VER}.macos10.xamarin.x86.dmg"
11 | - hdid "MonoFramework-MDK-${MONO_VER}.macos10.xamarin.x86.dmg"
12 | - sudo installer -pkg "/Volumes/Mono Framework MDK ${MONO_VER}/MonoFramework-MDK-${MONO_VER}.macos10.xamarin.x86.pkg" -target /
13 |
14 | script:
15 | - xbuild
16 | - /Library/Frameworks/Mono.framework/Versions/Current/bin/nunit-console4 -nodots -labels ./OmniSharp.Tests/bin/Debug/OmniSharp.Tests.dll
17 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Jason Imison
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/Microsoft.Build.Evaluation/Project.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Xml.Linq;
5 | using System.IO.Abstractions;
6 |
7 | namespace Microsoft.Build.Evaluation
8 | {
9 | public class Project
10 | {
11 |
12 | public string DirectoryPath { get; private set; }
13 |
14 | readonly XDocument document;
15 |
16 | public Project(IFileSystem fileSystem, string fileName)
17 | {
18 | DirectoryPath = fileSystem.Path.GetDirectoryName(fileName);
19 | var xml = fileSystem.File.ReadAllText(fileName);
20 | document = XDocument.Parse(xml);
21 | }
22 |
23 | public string GetPropertyValue(string name)
24 | {
25 | XElement element = document.Descendants(document.Root.Name.Namespace + "PropertyGroup").Descendants(document.Root.Name.Namespace + name).FirstOrDefault();
26 | return element == null ? string.Empty : element.Value;
27 | }
28 |
29 | public ICollection GetItems(string itemType)
30 | {
31 | IEnumerable elements = document.Descendants(document.Root.Name.Namespace + "ItemGroup").Descendants(document.Root.Name.Namespace + itemType);
32 | return (from element in elements select new ProjectItem(element)).ToList();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Microsoft.Build.Evaluation/ProjectItem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Xml.Linq;
7 |
8 | namespace Microsoft.Build.Evaluation
9 | {
10 | public class ProjectItem
11 | {
12 | private XElement Element;
13 | public ProjectItem(XElement element)
14 | {
15 | Element = element;
16 | }
17 | public string EvaluatedInclude
18 | {
19 | get
20 | {
21 | string value = this.Element.Attribute("Include").Value;
22 | if(value == null)
23 | return null;
24 |
25 | return System.Uri.UnescapeDataString(value);
26 | }
27 | }
28 | public bool HasMetadata(string name)
29 | {
30 | return Element.Descendants(Element.Document.Root.Name.Namespace + name).Any();
31 | }
32 | public string GetMetadataValue(string name)
33 | {
34 | return Element.Descendants(Element.Document.Root.Name.Namespace + name).First().Value;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Microsoft.Build.Evaluation/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Microsoft.Build.Evaluation")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Microsoft.Build.Evaluation")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("b4afb433-c90f-4e5f-b3c8-b1888f581b9f")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/AutoComplete/CompletionTestBase.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using OmniSharp.AutoComplete;
4 |
5 | namespace OmniSharp.Tests.AutoComplete
6 | {
7 | public class CompletionTestBase
8 | {
9 | protected IEnumerable DisplayTextFor(string input, bool includeImportableTypes = false)
10 | {
11 | return CompletionsDataFor(input, includeImportableTypes).Select(c => c.DisplayText);
12 | }
13 |
14 | protected IEnumerable CompletionsFor(string input, bool includeImportableTypes = false)
15 | {
16 | return CompletionsDataFor(input, includeImportableTypes).Select(c => c.CompletionText);
17 | }
18 |
19 | protected IEnumerable MethodHeaderFor(string input, bool includeImportableTypes = false)
20 | {
21 | return CompletionsDataFor(input, includeImportableTypes).Select(c => c.MethodHeader);
22 | }
23 |
24 | protected IEnumerable SnippetFor(string input, bool includeImportableTypes = false)
25 | {
26 | return CompletionsDataFor(input, includeImportableTypes).Select(c => c.Snippet);
27 | }
28 |
29 | protected IEnumerable ReturnTypeFor(string input, bool includeImportableTypes = false)
30 | {
31 | return CompletionsDataFor(input, includeImportableTypes).Select(c => c.ReturnType);
32 | }
33 |
34 | protected IEnumerable CompletionsDataFor(string input, bool includeImportableTypes = false)
35 | {
36 | return new CompletionsSpecBase().GetCompletions(input, includeImportableTypes);
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/OmniSharp.Tests/AutoComplete/CompletionsSpecBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text.RegularExpressions;
4 | using ICSharpCode.NRefactory;
5 | using OmniSharp.AutoComplete;
6 | using OmniSharp.Parser;
7 | using OmniSharp.Configuration;
8 |
9 | namespace OmniSharp.Tests.AutoComplete
10 | {
11 | public class CompletionsSpecBase
12 | {
13 | private readonly FakeSolution _solution;
14 |
15 | public CompletionsSpecBase()
16 | {
17 | _solution = new FakeSolution();
18 | }
19 |
20 | public IEnumerable GetCompletions(string editorText, bool includeImportableTypes)
21 | {
22 | int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal);
23 | if (cursorOffset == -1)
24 | throw new ArgumentException("Editor text should contain a $");
25 |
26 | TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset);
27 | string partialWord = GetPartialWord(editorText);
28 | editorText = editorText.Replace("$", "");
29 |
30 | var project = new FakeProject();
31 | project.AddFile(editorText);
32 | _solution.Projects.Add(project);
33 | var provider = new AutoCompleteHandler(_solution, new BufferParser(_solution), new Logger(Verbosity.Quiet), new OmniSharpConfiguration());
34 | var request = new AutoCompleteRequest
35 | {
36 | FileName = "myfile",
37 | WordToComplete = partialWord,
38 | Buffer = editorText,
39 | Line = cursorPosition.Line,
40 | Column = cursorPosition.Column,
41 | WantDocumentationForEveryCompletionResult = false,
42 | WantImportableTypes = includeImportableTypes,
43 | WantMethodHeader = true,
44 | WantReturnType = true,
45 | WantSnippet = true
46 | };
47 |
48 | return provider.CreateProvider(request);
49 | }
50 |
51 | private static string GetPartialWord(string editorText)
52 | {
53 | MatchCollection matches = Regex.Matches(editorText, @"([a-zA-Z0-9_]*)\$");
54 | return matches[0].Groups[1].ToString();
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/AutoComplete/DerivedTypeCompletions.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 |
3 | namespace OmniSharp.Tests.AutoComplete
4 | {
5 | [TestFixture]
6 | public class DerivedTypeCompletions : CompletionTestBase
7 | {
8 | [Test]
9 | public void Should_complete_derived_types()
10 | {
11 | DisplayTextFor(
12 | @"public class A {
13 | public A()
14 | {
15 | int n;
16 | n.GetHashCode$;
17 | }
18 | }").ShouldContainOnly("int GetHashCode()");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/AutoComplete/IntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Text.RegularExpressions;
4 | using ICSharpCode.NRefactory;
5 | using NUnit.Framework;
6 | using Nancy.Testing;
7 | using OmniSharp.AutoComplete;
8 | using OmniSharp.Solution;
9 | using Should;
10 |
11 | namespace OmniSharp.Tests.AutoComplete
12 | {
13 | [TestFixture]
14 | public class IntegrationTest
15 | {
16 | [Test]
17 | public void Should_complete_string()
18 | {
19 | string editorText = @"
20 | public class myclass
21 | {
22 | public void method()
23 | {
24 | string s;
25 | s.$;
26 | }
27 | }
28 | ";
29 | int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal);
30 | TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset);
31 | string partialWord = GetPartialWord(editorText);
32 | editorText = editorText.Replace("$", "");
33 |
34 | var solution = new FakeSolution();
35 | var project = new FakeProject();
36 | project.AddFile(editorText);
37 | solution.Projects.Add(project);
38 |
39 | var bootstrapper = new ConfigurableBootstrapper(c => c.Dependency(solution));
40 | var browser = new Browser(bootstrapper);
41 |
42 | var result = browser.Post("/autocomplete", with =>
43 | {
44 | with.HttpRequest();
45 | with.FormValue("FileName", "myfile");
46 | with.FormValue("WordToComplete", partialWord);
47 | with.FormValue("Buffer", editorText);
48 | with.FormValue("Line", cursorPosition.Line.ToString());
49 | with.FormValue("Column", cursorPosition.Column.ToString());
50 | });
51 |
52 | var res = result.Body.DeserializeJson().Select(c => c.DisplayText);
53 | res.ShouldContain("Trim()");
54 | }
55 |
56 | private static string GetPartialWord(string editorText)
57 | {
58 | MatchCollection matches = Regex.Matches(editorText, @"([a-zA-Z0-9_]*)\$");
59 | return matches[0].Groups[1].ToString();
60 | }
61 |
62 |
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/Build/BuildLogParserTests.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using OmniSharp.Build;
3 | using Should;
4 |
5 | namespace OmniSharp.Tests.Build
6 | {
7 | class BuildLogParserTests
8 | {
9 | [Test]
10 | public void Should_parse_syntax_error()
11 | {
12 | var logParser = new BuildLogParser();
13 | var quickfix = logParser.Parse(
14 | @" c:\_src\OmniSharp\server\OmniSharp\Program.cs(12,34): error CS1002: ; expected [C:\_src\OmniSharp\server\OmniSharp\OmniSharp.csproj]");
15 | quickfix.FileName.ShouldEqual(@"c:\_src\OmniSharp\server\OmniSharp\Program.cs");
16 | quickfix.Line.ShouldEqual(12);
17 | quickfix.Column.ShouldEqual(34);
18 | quickfix.Text.ShouldEqual(
19 | @"[error] ; expected");
20 |
21 | }
22 |
23 |
24 | [Test]
25 | public void Should_parse_missing_file_error()
26 | {
27 | var logParser = new BuildLogParser();
28 | var quickfix = logParser.Parse(
29 | @" CSC : error CS2001: Source file 'Bootstrapper.cs' could not be found [C:\_src\OmniSharp\server\OmniSharp\OmniSharp.csproj]");
30 | quickfix.Text.ShouldEqual(
31 | @"Source file ''Bootstrapper.cs'' could not be found [C:\_src\OmniSharp\server\OmniSharp\OmniSharp.csproj]");
32 | quickfix.FileName.ShouldEqual("Bootstrapper.cs");
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/CodeFormat/CodeFormatTest.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using OmniSharp.CodeFormat;
3 | using OmniSharp.Configuration;
4 | using Should;
5 |
6 | namespace OmniSharp.Tests.CodeFormat
7 | {
8 | [TestFixture]
9 | class CodeFormatTest
10 | {
11 | [Test]
12 | public void Should_format_code()
13 | {
14 | string code =
15 | @"public class Test {
16 | }";
17 |
18 | string expected =
19 | @"public class Test
20 | {
21 | }";
22 |
23 | var handler = new CodeFormatHandler(new OmniSharpConfiguration());
24 | var buffer = handler.Format(new CodeFormatRequest {Buffer = code}).Buffer;
25 | buffer.Replace("\r\n", "\n").ShouldEqual(expected);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/FakeAssembly.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ICSharpCode.NRefactory.TypeSystem;
3 |
4 | namespace OmniSharp.Tests
5 | {
6 | public class FakeAssembly : IAssemblyReference
7 | {
8 | private readonly string _assembly;
9 |
10 | public FakeAssembly(string assembly)
11 | {
12 | _assembly = assembly;
13 | }
14 |
15 | public string AssemblyPath { get { return _assembly; } }
16 |
17 | public IAssembly Resolve(ITypeResolveContext context)
18 | {
19 | throw new NotImplementedException();
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/OmniSharp.Tests/FakeFileSystem.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using OmniSharp.Common;
3 |
4 | namespace OmniSharp.Tests
5 | {
6 | public class FakeWindowsFileSystem : FakeFileSystem
7 | {
8 | public FakeWindowsFileSystem () : base(@"\") {}
9 | }
10 |
11 | public class FakeUnixFileSystem : FakeFileSystem
12 | {
13 | public FakeUnixFileSystem () : base("/") {}
14 | }
15 |
16 | public class FakeFileSystem : IFileSystem
17 | {
18 | private string _pathSeparator;
19 | private bool _exists = true;
20 |
21 | public FakeFileSystem ()
22 | {
23 | _pathSeparator = @"\";
24 | }
25 |
26 | public FakeFileSystem (string pathSeparator)
27 | {
28 | _pathSeparator = pathSeparator;
29 | }
30 |
31 | public string GetDirectoryName(string filename)
32 | {
33 | return filename.Substring (0, filename.LastIndexOf (_pathSeparator, System.StringComparison.Ordinal));
34 | }
35 |
36 | public void FileExists(bool exists)
37 | {
38 | _exists = exists;
39 | }
40 |
41 | public FileInfo GetFileInfo(string filename)
42 | {
43 | if(_exists)
44 | return new FileInfo("Nancy.dll");
45 |
46 | return new FileInfo("IDontExist.dll");
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/OmniSharp.Tests/FakeProject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO.Abstractions.TestingHelpers;
4 | using ICSharpCode.NRefactory.CSharp;
5 | using ICSharpCode.NRefactory.TypeSystem;
6 | using OmniSharp.Solution;
7 | using System.Linq;
8 |
9 | namespace OmniSharp.Tests
10 | {
11 | public class FakeProject : Project
12 | {
13 | static readonly Lazy mscorlib
14 | = new Lazy(() => new CecilLoader().LoadAssemblyFile(typeof(object).Assembly.Location));
15 |
16 | static readonly Lazy systemCore
17 | = new Lazy(() => new CecilLoader().LoadAssemblyFile(typeof(Enumerable).Assembly.Location));
18 |
19 |
20 |
21 | public FakeProject(string name = "fake", string fileName = "fake.csproj", Guid id = new Guid())
22 | : base(new MockFileSystem(), new Logger(Verbosity.Quiet))
23 | {
24 | Name = name;
25 | FileName = fileName;
26 | Files = new List();
27 | References = new List();
28 | ProjectId = id;
29 | this.ProjectContent
30 | = new CSharpProjectContent()
31 | .SetAssemblyName(name)
32 | .SetProjectFileName(name)
33 | .AddAssemblyReferences(new [] { mscorlib.Value, systemCore.Value });
34 | }
35 |
36 | public void AddFile(string source, string fileName = "myfile")
37 | {
38 | Files.Add(new CSharpFile(this, fileName, source));
39 | this.ProjectContent = this.ProjectContent
40 | .AddOrUpdateFiles(Files.Select(f => f.ParsedFile));
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/OmniSharp.Tests/FakeSolution.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using OmniSharp.Solution;
5 |
6 | namespace OmniSharp.Tests
7 | {
8 | public class FakeSolution : ISolution
9 | {
10 | public FakeSolution()
11 | {
12 | Projects = new List();
13 | }
14 |
15 | public bool Loaded
16 | {
17 | get
18 | {
19 | return true;
20 | }
21 | }
22 |
23 | public FakeSolution(string filename) : this()
24 | {
25 | FileName = filename;
26 | }
27 |
28 | public List Projects { get; private set; }
29 | public string FileName { get; private set; }
30 |
31 | public CSharpFile GetFile(string filename)
32 | {
33 | return (from project in Projects
34 | from file in project.Files
35 | where file.FileName == filename
36 | select file).FirstOrDefault();
37 | }
38 |
39 | public IProject ProjectContainingFile(string filename)
40 | {
41 | return Projects.FirstOrDefault(p => p.Files.Any(f => f.FileName.Equals(filename, StringComparison.InvariantCultureIgnoreCase)));
42 | }
43 |
44 | public void Reload()
45 | {
46 | throw new NotImplementedException();
47 | }
48 |
49 | public void Terminate()
50 | {
51 | throw new NotImplementedException();
52 | }
53 |
54 | public void LoadSolution()
55 | {
56 | throw new NotImplementedException();
57 | }
58 |
59 | public bool Terminated { get; private set; }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/FindUsages/IntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using NUnit.Framework;
3 | using Nancy.Testing;
4 | using OmniSharp.Common;
5 | using OmniSharp.Solution;
6 | using Should;
7 | using OmniSharp.FindUsages;
8 |
9 | namespace OmniSharp.Tests.FindUsages
10 | {
11 | [TestFixture]
12 | public class IntegrationTest
13 | {
14 | [Test]
15 | public void Should_find_usages_of_class()
16 | {
17 | const string editorText =
18 | @"public class myclass
19 | {
20 | public void method() { }
21 |
22 | public void method_calling_method()
23 | {
24 | method();
25 | }
26 | }
27 | ";
28 | var solution = new FakeSolution();
29 | var project = new FakeProject();
30 | project.AddFile(editorText);
31 | solution.Projects.Add(project);
32 |
33 | var handler = new FindUsagesHandler (new OmniSharp.Parser.BufferParser (solution), solution, new ProjectFinder(solution));
34 | var usages = handler.FindUsages (new FindUsagesRequest {
35 | FileName = "myfile",
36 | Line = 3,
37 | Column = 21,
38 | Buffer = editorText
39 | }).QuickFixes.ToArray();
40 |
41 | usages.Length.ShouldEqual(2);
42 | usages[0].Text.Trim().ShouldEqual("public void method() { }");
43 | usages[1].Text.Trim().ShouldEqual("method();");
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/Overrides/TestOverrideContext.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using NUnit.Framework;
3 | using Should;
4 | using OmniSharp.Common;
5 | using OmniSharp.Overrides;
6 | using OmniSharp.Parser;
7 | using OmniSharp.Tests.Rename;
8 | using OmniSharp.Configuration;
9 |
10 | namespace OmniSharp.Tests.Overrides
11 | {
12 | [TestFixture]
13 | public class OverridesTest
14 | {
15 | [Test]
16 | public void Should_not_offer_already_overridden_method()
17 | {
18 | var buffer = @"
19 | public class WeirdString : String
20 | {
21 | public override string ToString()
22 | {
23 | return ""weird"";
24 | }
25 | $
26 | }";
27 | var location = TestHelpers.GetLineAndColumnFromDollar(buffer);
28 | var request = new Request { Buffer = buffer, FileName = "myfile.cs", Line = location.Line, Column = location.Column };
29 | var solution = new FakeSolutionBuilder().AddFile(buffer, "myfile.cs").Build();
30 | var parser = new BufferParser(solution);
31 |
32 | var context = new OverrideContext(request, parser);
33 | var overrides = context.OverrideTargets.Select(m => m.OverrideTargetName).ToArray();
34 | overrides.ShouldNotContain("public virtual string ToString ();");
35 |
36 | }
37 |
38 | [Test]
39 | public void Should_insert_stub_method_override()
40 | {
41 | var buffer =
42 | @"
43 | public class WeirdString : String
44 | {
45 | $
46 | }";
47 | var location = TestHelpers.GetLineAndColumnFromDollar(buffer);
48 | buffer = buffer.Replace("$","");
49 | var request = new RunOverrideTargetRequest { Buffer = buffer, FileName = "myfile.cs", Line = location.Line, Column = location.Column };
50 | var solution = new FakeSolutionBuilder().AddFile(buffer, "myfile.cs").Build();
51 | var parser = new BufferParser(solution);
52 | var handler = new OverrideHandler (parser, new OmniSharpConfiguration ());
53 | request.OverrideTargetName = "public virtual string ToString ();";
54 | var response = handler.RunOverrideTarget (request);
55 | string expected =
56 | @"
57 | public class WeirdString : String
58 | {
59 |
60 | public override string ToString()
61 | {
62 | throw new System.NotImplementedException();
63 | }
64 | }";
65 | string result = response.Buffer.Replace ("\r\n", "\n");
66 | result.ShouldEqual(expected);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/ProjectManipulation/AddReference/MockProject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO.Abstractions;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 | using ICSharpCode.NRefactory.TypeSystem.Implementation;
5 | using OmniSharp.Solution;
6 |
7 | namespace OmniSharp.Tests.ProjectManipulation.AddReference
8 | {
9 | public class MockProject : CSharpProject
10 | {
11 | public MockProject (ISolution solution, IFileSystem fileSystem, Logger logger, string fileName)
12 | : base(solution, fileSystem, logger, "name", fileName, Guid.NewGuid())
13 | {
14 |
15 | }
16 |
17 | public override IUnresolvedAssembly LoadAssembly(string assemblyFileName)
18 | {
19 | return new DefaultUnresolvedAssembly(assemblyFileName);
20 | }
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/OmniSharp.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Omnisharp.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Omnisharp.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("10669f44-1cdc-4623-b034-43eaca70e915")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/Rename/Buffer.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.Tests.Rename
2 | {
3 | public class Buffer
4 | {
5 | public string Text { get; set; }
6 | public string Filename { get; set; }
7 |
8 | public Buffer(string text, string filename)
9 | {
10 | Text = text;
11 | Filename = filename;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/OmniSharp.Tests/Rename/FakeSolutionBuilder.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 | using OmniSharp.Solution;
5 |
6 | namespace OmniSharp.Tests.Rename
7 | {
8 | public class FakeSolutionBuilder
9 | {
10 | private readonly FakeSolution _solution;
11 | private readonly FakeProject _project;
12 | private readonly List _projects = new List();
13 |
14 | private int projectCount = 1;
15 | public FakeSolutionBuilder()
16 | {
17 | _solution = new FakeSolution();
18 | _project = new FakeProject("Project" + projectCount++);
19 | _projects.Add(_project);
20 | }
21 |
22 | public FakeSolutionBuilder AddProject()
23 | {
24 | var newProject = new FakeProject("Project" + projectCount++);
25 |
26 | foreach (var project in _projects)
27 | {
28 | // each project references the ones that came before it.
29 | newProject.AddReference(new ICSharpCode.NRefactory.TypeSystem.ProjectReference(project.Name));
30 | }
31 | _projects.Add(newProject);
32 |
33 | return this;
34 | }
35 |
36 | public FakeSolutionBuilder AddFile(string buffer, string fileName = "myfile")
37 | {
38 | _projects.Last().AddFile(buffer, fileName);
39 | return this;
40 | }
41 |
42 | public FakeSolution Build()
43 | {
44 | foreach(var project in _projects)
45 | _solution.Projects.Add(project);
46 | return _solution;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/ShouldExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using NUnit.Framework;
4 | using System.Xml.Linq;
5 |
6 | namespace OmniSharp.Tests
7 | {
8 | public static class ShouldExtensions
9 | {
10 | public static void ShouldEqual(this string actual, string expected)
11 | {
12 | Assert.AreEqual(expected, actual);
13 | }
14 |
15 | public static void ShouldEqual(this IEnumerable actual, params T[] expected)
16 | {
17 | CollectionAssert.AreEqual(expected, actual.ToArray());
18 | }
19 |
20 | public static void ShouldEqual(this XDocument actual, XDocument expected)
21 | {
22 | actual.ToString().ShouldEqual(expected.ToString());
23 | }
24 |
25 | public static void ShouldEqualXml(this string actual, string expected)
26 | {
27 | XDocument.Parse(actual).ShouldEqual(XDocument.Parse(expected));
28 | }
29 |
30 | public static void ShouldContainOnly(this IEnumerable actual, params T[] expected)
31 | {
32 | actual.ShouldContainOnly(new List(expected));
33 | }
34 |
35 | public static void ShouldContain(this IEnumerable actual, params T[] expected)
36 | {
37 | var actualList = new List(actual);
38 | foreach (T item in expected)
39 | {
40 | Assert.Contains(item, actualList);
41 | }
42 | }
43 |
44 | public static void ShouldNotContain(this IEnumerable actual, params T[] expected)
45 | {
46 | var actualList = new List(actual);
47 | foreach (T item in expected)
48 | {
49 | CollectionAssert.DoesNotContain(actualList, item);
50 | }
51 | }
52 |
53 | public static void ShouldContainOnly(this IEnumerable actual, IEnumerable expected)
54 | {
55 | var actualList = new List(actual);
56 | var remainingList = new List(actualList);
57 | foreach (T item in expected)
58 | {
59 | Assert.Contains(item, actualList);
60 | remainingList.Remove(item);
61 | }
62 | Assert.IsEmpty(remainingList);
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/Solution/minimal/minimal.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "minimal", "minimal\minimal.csproj", "{3B841ABF-EEA2-4BE2-B14F-20EE639F10BF}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {3B841ABF-EEA2-4BE2-B14F-20EE639F10BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {3B841ABF-EEA2-4BE2-B14F-20EE639F10BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {3B841ABF-EEA2-4BE2-B14F-20EE639F10BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {3B841ABF-EEA2-4BE2-B14F-20EE639F10BF}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(MonoDevelopProperties) = preSolution
18 | StartupItem = minimal\minimal.csproj
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/Solution/minimal/minimal/MyClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace minimal
4 | {
5 | public class MyClass
6 | {
7 | public MyClass ()
8 | {
9 | }
10 | }
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/Solution/minimal/minimal/MyClassContainer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace minimal
4 | {
5 | // Holds a reference to MyClass. Used for "go to definition" tests
6 | // across files.
7 | public class MyClassContainer
8 | {
9 | public MyClass foo;
10 | }
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/Solution/minimal/minimal/minimal.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 10.0.0
7 | 2.0
8 | {3B841ABF-EEA2-4BE2-B14F-20EE639F10BF}
9 | Library
10 | minimal
11 | minimal
12 |
13 |
14 | true
15 | full
16 | false
17 | bin\Debug
18 | DEBUG;
19 | prompt
20 | 4
21 | false
22 |
23 |
24 | full
25 | true
26 | bin\Release
27 | prompt
28 | 4
29 | false
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/TestHelpers.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.NRefactory;
2 | using System;
3 |
4 | namespace OmniSharp.Tests
5 | {
6 | public static class TestHelpers
7 | {
8 | public static TextLocation GetLineAndColumnFromDollar(string text)
9 | {
10 | var indexOfDollar = text.IndexOf("$");
11 |
12 | if (indexOfDollar == -1)
13 | throw new ArgumentException("Expected a $ sign in test input");
14 |
15 | return GetLineAndColumnFromIndex(text, indexOfDollar);
16 | }
17 |
18 | public static TextLocation GetLineAndColumnFromIndex(string text, int index)
19 | {
20 | int lineCount = 1, lastLineEnd = -1;
21 | for (int i = 0; i < index; i++)
22 | if (text[i] == '\n')
23 | {
24 | lineCount++;
25 | lastLineEnd = i;
26 | }
27 |
28 | return new TextLocation(lineCount, index - lastLineEnd);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/TypeLookup/EmptyResults.cs:
--------------------------------------------------------------------------------
1 | using Should;
2 | using NUnit.Framework;
3 |
4 | namespace OmniSharp.Tests.TypeLookup
5 | {
6 | [TestFixture]
7 | public class EmptyResults
8 | {
9 | [Test]
10 | public void LookupWhiteSpace()
11 | {
12 | @"
13 | public class Test
14 | {
15 | $ public void static Main()
16 | {
17 | int name = 10;
18 | name++;
19 | }
20 | }".LookupType().ShouldEqual("");
21 | }
22 |
23 | [Test]
24 | public void LookupKeyword()
25 | {
26 | @"
27 | public class Test
28 | {
29 | public sta$tic void Main()
30 | {
31 | int name = 10;
32 | name++;
33 | }
34 | }".LookupType().ShouldEqual("");
35 | }
36 |
37 | [Test]
38 | public void LookupNamespace()
39 | {
40 | @"
41 | using Sys$tem;
42 | public class Test
43 | {
44 | public static void Main()
45 | {
46 | int name = 10;
47 | name++;
48 | }
49 | }".LookupType().ShouldEqual("");
50 | }
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/TypeLookup/IntegrationTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ICSharpCode.NRefactory;
3 | using NUnit.Framework;
4 | using Nancy.Testing;
5 | using OmniSharp.TypeLookup;
6 | using OmniSharp.Solution;
7 | using Should;
8 |
9 | namespace OmniSharp.Tests.TypeLookup
10 | {
11 | [TestFixture]
12 | public class IntegrationTest
13 | {
14 | [Test]
15 | public void Should_lookup_Test()
16 | {
17 | string editorText = @"
18 | public class Test
19 | {
20 | public void Main()
21 | {
22 | Test test;
23 | te$st = new Test();
24 | }
25 | }
26 | ";
27 | int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal);
28 | TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset);
29 | editorText = editorText.Replace("$", "");
30 |
31 | var solution = new FakeSolution();
32 | var project = new FakeProject();
33 | project.AddFile(editorText);
34 | solution.Projects.Add(project);
35 |
36 | var bootstrapper = new ConfigurableBootstrapper(c => c.Dependency(solution));
37 | var browser = new Browser(bootstrapper);
38 |
39 | var result = browser.Post("/typelookup", with =>
40 | {
41 | with.HttpRequest();
42 | with.FormValue("FileName", "myfile");
43 | with.FormValue("Buffer", editorText);
44 | with.FormValue("Line", cursorPosition.Line.ToString());
45 | with.FormValue("Column", cursorPosition.Column.ToString());
46 | });
47 |
48 | var res = result.Body.DeserializeJson();
49 | res.Type.ShouldEqual("Test test");
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/TypeLookup/LocalVariables.cs:
--------------------------------------------------------------------------------
1 | using Should;
2 | using NUnit.Framework;
3 |
4 | namespace OmniSharp.Tests.TypeLookup
5 | {
6 | [TestFixture]
7 | public class LocalVariables
8 | {
9 | [Test]
10 | public void Should_LookupInt()
11 | {
12 | @"
13 | public class Test
14 | {
15 | public static void Main()
16 | {
17 | int na$me = 10;
18 | }
19 | }
20 | ".LookupType().ShouldEqual("int name");
21 | }
22 |
23 | [Test]
24 | public void Should_LookupInt_From_var1()
25 | {
26 | @"
27 | public class Test
28 | {
29 | public static void Main()
30 | {
31 | var na$me = 10;
32 | }
33 | }
34 | ".LookupType().ShouldEqual("int name");
35 | }
36 |
37 | [Test]
38 | public void Should_LookupInt_From_var2()
39 | {
40 | @"
41 | public class Test
42 | {
43 | public static void Main()
44 | {
45 | va$r name = 10;
46 | }
47 | }
48 | ".LookupType().ShouldEqual("int");
49 | }
50 |
51 | [Test]
52 | public void Should_LookupInt_From_var3()
53 | {
54 | @"
55 | public class Test
56 | {
57 | public static void Main()
58 | {
59 | var name = 10;
60 | nam$e++;
61 | }
62 | }
63 | ".LookupType().ShouldEqual("int name");
64 | }
65 |
66 | [Test, Ignore("wip")]
67 | public void Should_LookupTest_From_var()
68 | {
69 | @"
70 | public class Test
71 | {
72 | public static void Main()
73 | {
74 | va$r name = new Test();
75 | }
76 | }
77 | ".LookupType().ShouldEqual("Test");
78 | }
79 |
80 | [Test]
81 | public void Should_LookupDelegate()
82 | {
83 | @"
84 | public delegate void Run();
85 | public class Test
86 | {
87 | public static void Main()
88 | {
89 | Run run = Main;
90 | r$un();
91 | }
92 | }
93 | ".LookupType().ShouldEqual("Run run");
94 | }
95 |
96 | [Test]
97 | public void Should_LookupUnknown()
98 | {
99 | @"
100 | public class Test
101 | {
102 | public void Main()
103 | {
104 | FakeType ty$pe;
105 | type = null;
106 | }
107 | }
108 | ".LookupType().ShouldEqual("Unknown Type");
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/TypeLookup/MemberVariables.cs:
--------------------------------------------------------------------------------
1 | using Should;
2 | using NUnit.Framework;
3 |
4 | namespace OmniSharp.Tests.TypeLookup
5 | {
6 | [TestFixture]
7 | public class MemberVariables
8 | {
9 | [Test]
10 | public void Should_LookupInt1()
11 | {
12 | @"
13 | public class Test
14 | {
15 | private int _$i;
16 | public Test()
17 | {
18 | _i = 10;
19 | }
20 | }
21 | ".LookupType().ShouldEqual("int Test._i;");
22 | }
23 |
24 | [Test]
25 | public void Should_LookupInt2()
26 | {
27 | @"
28 | public class Test
29 | {
30 | private int _i;
31 | public Test()
32 | {
33 | _$i = 10;
34 | }
35 | }
36 | ".LookupType().ShouldEqual("int Test._i;");
37 | }
38 |
39 | [Test]
40 | public void Should_LookupInt_static()
41 | {
42 | @"
43 | public class Test
44 | {
45 | private static int _i;
46 | public Test()
47 | {
48 | _$i = 10;
49 | }
50 | }
51 | ".LookupType().ShouldEqual("static int Test._i;");
52 | }
53 |
54 | [Test]
55 | public void Should_LookupString_static()
56 | {
57 | @"
58 | public static class ClassA
59 | {
60 | public static string Name = ""Name"";
61 | }
62 |
63 | public class Test
64 | {
65 | public void Main()
66 | {
67 | string s = ClassA.Na$me;
68 | }
69 | }
70 | ".LookupType().ShouldEqual("static string ClassA.Name;");
71 | }
72 |
73 | [Test]
74 | public void Should_LookupInstanceString()
75 | {
76 | @"
77 | public class Test
78 | {
79 | private string _name;
80 | public void Main()
81 | {
82 | var t = new Test();
83 | t._n$ame = ""Test""
84 | }
85 | }
86 | ".LookupType().ShouldEqual("string Test._name;");
87 | }
88 |
89 | [Test]
90 | public void Should_LookupUnknown()
91 | {
92 | @"
93 | public class Test
94 | {
95 | private String _name;
96 | public void Main()
97 | {
98 | var t = new Test();
99 | t._n$ame = ""Test""
100 | }
101 | }
102 | ".LookupType().ShouldEqual("Unknown Type: String");
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/TypeLookup/Methods.cs:
--------------------------------------------------------------------------------
1 | using Should;
2 | using NUnit.Framework;
3 |
4 | namespace OmniSharp.Tests.TypeLookup
5 | {
6 | [TestFixture]
7 | public class Methods
8 | {
9 | [Test]
10 | public void Should_Lookup_ReturnString_NoArgs()
11 | {
12 | @"
13 | public class Test
14 | {
15 | public string MethodA()
16 | {
17 | return ""Test"";
18 | }
19 |
20 | public static void Main()
21 | {
22 | var t = new Test();
23 | t.M$ethodA();
24 | }
25 | }
26 | ".LookupType().ShouldEqual("string Test.MethodA();");
27 | }
28 |
29 | [Test]
30 | public void Should_LookupStatic_ReturnTest_OneArg()
31 | {
32 | @"
33 | public class Test
34 | {
35 | public static Test Create(string s)
36 | {
37 | return new Test();
38 | }
39 |
40 | public static void Main()
41 | {
42 | var t = Creat$e();
43 | }
44 | }
45 | ".LookupType().ShouldEqual("static Test Test.Create(string s);");
46 | }
47 |
48 | [Test]
49 | public void Should_LookupConstructor_NoArgs()
50 | {
51 | @"
52 | public class Test
53 | {
54 |
55 | public static void Main()
56 | {
57 | var t = new Te$st();
58 | }
59 | }
60 | ".LookupType().ShouldEqual("Test.Test();");
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/TypeLookup/Properties.cs:
--------------------------------------------------------------------------------
1 | using Should;
2 | using NUnit.Framework;
3 |
4 | namespace OmniSharp.Tests.TypeLookup
5 | {
6 | [TestFixture]
7 | public class Properties
8 | {
9 | [Test]
10 | public void Should_LookupInt1()
11 | {
12 | @"
13 | public class Test
14 | {
15 | private int Co$unt { get; set; };
16 | public Test()
17 | {
18 | Count = 10;
19 | }
20 | }
21 | ".LookupType().ShouldEqual("int Test.Count { get; set; }");
22 | }
23 |
24 | [Test]
25 | public void Should_LookupInt2()
26 | {
27 | @"
28 | public class Test
29 | {
30 | private int Count { get; set; };
31 | public Test()
32 | {
33 | $Count = 10;
34 | }
35 | }
36 | ".LookupType().ShouldEqual("int Test.Count { get; set; }");
37 | }
38 |
39 | [Test]
40 | public void Should_LookupInt_static()
41 | {
42 | @"
43 | public class Test
44 | {
45 | private static int C$ount { get; set; };
46 | public Test()
47 | {
48 | Count = 10;
49 | }
50 | }
51 | ".LookupType().ShouldEqual("static int Test.Count { get; set; }");
52 | }
53 |
54 | [Test]
55 | public void Should_LookupString_static()
56 | {
57 | @"
58 | public static class ClassA
59 | {
60 | public static string Name { get; set; }
61 | }
62 |
63 | public class Test
64 | {
65 | public void Main()
66 | {
67 | string s = ClassA.Na$me;
68 | }
69 | }
70 | ".LookupType().ShouldEqual("static string ClassA.Name { get; set; }");
71 | }
72 |
73 | [Test]
74 | public void Should_LookupInstanceString()
75 | {
76 | @"
77 | public class Test
78 | {
79 | private string Name { get; set; }
80 | public void Main()
81 | {
82 | var t = new Test();
83 | t.N$ame = ""Test""
84 | }
85 | }
86 | ".LookupType().ShouldEqual("string Test.Name { get; set; }");
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/TypeLookup/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using OmniSharp.Parser;
3 | using OmniSharp.TypeLookup;
4 | using OmniSharp.Configuration;
5 |
6 | namespace OmniSharp.Tests.TypeLookup
7 | {
8 | public static class StringExtensions
9 | {
10 | public static string LookupType(this string editorText)
11 | {
12 | int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal);
13 | var cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset);
14 | editorText = editorText.Replace("$", "");
15 |
16 | var solution = new FakeSolution();
17 | var project = new FakeProject();
18 | project.AddFile(editorText);
19 | solution.Projects.Add(project);
20 |
21 | var handler = new TypeLookupHandler(solution, new BufferParser(solution), new OmniSharpConfiguration());
22 | var request = new TypeLookupRequest()
23 | {
24 | Buffer = editorText,
25 | FileName = "myfile",
26 | Line = cursorPosition.Line,
27 | Column = cursorPosition.Column,
28 | };
29 |
30 | return handler.GetTypeLookupResponse(request).Type;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/UnitTesting/UnitTesting.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using OmniSharp.Parser;
3 | using OmniSharp.TestContextInformation;
4 |
5 | namespace OmniSharp.Tests.UnitTesting
6 | {
7 | public static class CreateContextLookup
8 | {
9 | public static GetContextResponse GetContextInformation(this string editorText)
10 | {
11 | var cursorPosition = TestHelpers.GetLineAndColumnFromDollar(editorText);
12 | editorText = editorText.Replace("$", "");
13 |
14 | var solution = new FakeSolution();
15 | var project = new FakeProject();
16 | project.AddFile(editorText);
17 | solution.Projects.Add(project);
18 |
19 | var handler = new GetTestContextHandler(solution, new BufferParser(solution));
20 | var request = new TestCommandRequest
21 | {
22 | Buffer = editorText,
23 | FileName = "myfile",
24 | Line = cursorPosition.Line,
25 | Column = cursorPosition.Column,
26 | };
27 |
28 | return handler.GetContextResponse(request);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/OmniSharp.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/AutoCompleteModule.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using Nancy;
3 | using Nancy.ModelBinding;
4 |
5 | namespace OmniSharp.AutoComplete
6 | {
7 | public class AutoCompleteModule : NancyModule
8 | {
9 | public AutoCompleteModule(AutoCompleteHandler autoCompleteHandler)
10 | {
11 | Post["AutoComplete", "/autocomplete"] = x =>
12 | {
13 | var req = this.Bind();
14 | var completions = autoCompleteHandler.CreateProvider(req);
15 | return Response.AsJson(completions.Select(c => new AutoCompleteResponse(c)));
16 | };
17 | }
18 |
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/AutoCompleteRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.AutoComplete
4 | {
5 | public class AutoCompleteRequest : Request
6 | {
7 | private string _wordToComplete;
8 | public string WordToComplete
9 | {
10 | get
11 | {
12 | return _wordToComplete ?? "";
13 | }
14 | set
15 | {
16 | _wordToComplete = value;
17 | }
18 | }
19 |
20 | ///
21 | /// Specifies whether to force semantic completion (i.e. CTRL-space in
22 | /// NRefactory).
23 | ///
24 | public bool? ForceSemanticCompletion { get; set; }
25 |
26 | ///
27 | /// Specifies whether to return the code documentation for
28 | /// each and every returned autocomplete result.
29 | ///
30 | public bool WantDocumentationForEveryCompletionResult { get; set; }
31 |
32 | ///
33 | /// Specifies whether to return importable types. Defaults to
34 | /// false. Can be turned off to get a small speed boost.
35 | ///
36 | public bool WantImportableTypes { get; set; }
37 |
38 | ///
39 | /// Returns a 'method header' for working with parameter templating.
40 | ///
41 | public bool WantMethodHeader { get; set; }
42 |
43 | ///
44 | /// Returns a snippet that can be used by common snippet libraries
45 | /// to provide parameter and type parameter placeholders
46 | ///
47 | public bool WantSnippet { get; set; }
48 |
49 | ///
50 | /// Returns the return type
51 | ///
52 | public bool WantReturnType { get; set; }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/AutoCompleteResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.AutoComplete
2 | {
3 | public class AutoCompleteResponse
4 | {
5 | public AutoCompleteResponse() { } // for deserialisation
6 |
7 | public AutoCompleteResponse(CompletionData d)
8 | {
9 | DisplayText = d.DisplayText;
10 | CompletionText = d.CompletionText;
11 | Description = d.Description;
12 | RequiredNamespaceImport = d.RequiredNamespaceImport;
13 | MethodHeader = d.MethodHeader;
14 | ReturnType = d.ReturnType;
15 | Snippet = d.Snippet;
16 | }
17 |
18 | public string CompletionText { get; private set; }
19 | public string Description { get; private set; }
20 | public string DisplayText { get; private set; }
21 | public string RequiredNamespaceImport { get; private set; }
22 | public string MethodHeader { get; private set; }
23 | public string ReturnType { get; private set; }
24 | public string Snippet { get; private set; }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/CompletionDataExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using ICSharpCode.NRefactory.Completion;
4 |
5 | namespace OmniSharp.AutoComplete
6 | {
7 | public static class CompletionDataExtensions
8 | {
9 | public static IEnumerable FlattenOverloads(this IEnumerable completions)
10 | {
11 | var res = new List();
12 | foreach (var completion in completions)
13 | {
14 | res.AddRange(completion.HasOverloads ? completion.OverloadedData.Cast() : new[] { completion });
15 | }
16 | return res;
17 | }
18 |
19 | public static IEnumerable RemoveDupes(this IEnumerable data)
20 | {
21 | return data.GroupBy(x => x.DisplayText,
22 | (k, g) => g.Aggregate((a, x) => (CompareTo(x, a) == -1) ? x : a));
23 | }
24 |
25 | private static int CompareTo(ICompletionData a, ICompletionData b)
26 | {
27 | if (a.CompletionCategory == null && b.CompletionCategory == null)
28 | return 0;
29 | if (a.CompletionCategory == null)
30 | return -1;
31 | if (b.CompletionCategory == null)
32 | return 1;
33 | return a.CompletionCategory.CompareTo(b.CompletionCategory);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/Metadata/AutoCompleteMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.AutoComplete.Metadata
5 | {
6 | public class AutoCompleteMetadataModule : MetadataModule
7 | {
8 |
9 | public AutoCompleteMetadataModule()
10 | {
11 | Describe["AutoComplete"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/autocomplete")
13 | .Summary("Get completions at the text location")
14 | .BodyParam(null, true)
15 | .Response(200)
16 | .Model());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/Metadata/AutoCompleteRequestMetadataProvider.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Swagger;
2 | using Nancy.Swagger.Services;
3 |
4 | namespace OmniSharp.AutoComplete.Metadata
5 | {
6 | public class AutoCompleteRequestMetadataProvider : ISwaggerModelDataProvider
7 | {
8 | public SwaggerModelData GetModelData()
9 | {
10 | return SwaggerModelData.ForType(builder =>
11 | {
12 | builder.Property(r => r.WordToComplete).Required(true);
13 | builder.Property(r => r.WantDocumentationForEveryCompletionResult).Description("Specifies whether to return the code documentation for each and every returned autocomplete result.");
14 | builder.Property(r => r.WantImportableTypes).Description("Specifies whether to return importable types. Defaults to false. Can be turned off to get a small speed boost.");
15 | builder.Property(r => r.WantMethodHeader).Description("Returns a 'method header' for working with parameter templating.");
16 | builder.Property(r => r.WantSnippet).Description("Returns a snippet that can be used by common snippet libraries to provide parameter and type parameter placeholders");
17 | builder.Property(r => r.WantReturnType).Description("Returns the return type ");
18 | });
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/Metadata/AutoCompleteResponseMetadataProvider.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Swagger;
2 | using Nancy.Swagger.Services;
3 |
4 | namespace OmniSharp.AutoComplete.Metadata
5 | {
6 | public class AutoCompleteResponseMetadataProvider : ISwaggerModelDataProvider
7 | {
8 | public SwaggerModelData GetModelData()
9 | {
10 | return SwaggerModelData.ForType(builder =>
11 | {
12 | builder.Description("Response");
13 | builder.Property(r => r.MethodHeader).Default(null); //?
14 | });
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/MyCompletionCategory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ICSharpCode.NRefactory.Completion;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 |
5 | namespace OmniSharp.AutoComplete
6 | {
7 | public class MyCompletionsCategory : CompletionCategory
8 | {
9 | public MyCompletionsCategory(SymbolKind entityType)
10 | {
11 | DisplayText = GetVimKind(entityType);
12 | }
13 |
14 | public MyCompletionsCategory()
15 | {
16 | DisplayText = " ";
17 | }
18 |
19 | private string GetVimKind(SymbolKind entityType)
20 | {
21 | // v variable
22 | //f function or method
23 | //m member of a struct or class
24 | switch(entityType)
25 | {
26 | case(SymbolKind.Method):
27 | return "f";
28 | case(SymbolKind.Field):
29 | return "v";
30 | case(SymbolKind.Property):
31 | return "m";
32 | }
33 | return " ";
34 | }
35 |
36 | public override int CompareTo(CompletionCategory other)
37 | {
38 | return String.CompareOrdinal(this.DisplayText, other.DisplayText);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/ReturnTypeAmbience.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.NRefactory.CSharp;
2 | using ICSharpCode.NRefactory.TypeSystem;
3 | using System.IO;
4 | using ICSharpCode.NRefactory.CSharp.Refactoring;
5 |
6 | namespace OmniSharp.AutoComplete
7 | {
8 | public class ReturnTypeAmbience
9 | {
10 | public string ConvertSymbol(ISymbol symbol)
11 | {
12 | var stringWriter = new StringWriter();
13 | var astBuilder = new TypeSystemAstBuilder();
14 | astBuilder.AlwaysUseShortTypeNames = true;
15 | AstNode node = astBuilder.ConvertSymbol(symbol);
16 | var writer = new TextWriterTokenWriter (stringWriter);
17 | var rt = node.GetChildByRole (Roles.Type);
18 | if (!rt.IsNull)
19 | {
20 | rt.AcceptVisitor (new CSharpOutputVisitor (stringWriter, FormattingOptionsFactory.CreateMono()));
21 |
22 | }
23 |
24 | IProperty property = symbol as IProperty;
25 | if (property != null)
26 | {
27 | writer.Space ();
28 | writer.WriteToken (Roles.LBrace, "{");
29 | writer.Space ();
30 | if (property.CanGet)
31 | {
32 | writer.WriteKeyword (PropertyDeclaration.GetKeywordRole, "get");
33 | writer.WriteToken (Roles.Semicolon, ";");
34 | writer.Space ();
35 | }
36 | if (property.CanSet)
37 | {
38 | writer.WriteKeyword (PropertyDeclaration.SetKeywordRole, "set");
39 | writer.WriteToken (Roles.Semicolon, ";");
40 | writer.Space ();
41 | }
42 | writer.WriteToken (Roles.RBrace, "}");
43 | }
44 | return stringWriter.ToString();
45 |
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/OmniSharp/AutoComplete/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using OmniSharp.Configuration;
3 |
4 | namespace OmniSharp.AutoComplete
5 | {
6 | public static class StringExtensions
7 | {
8 | public static bool IsValidCompletionFor(this string completion, string partial)
9 | {
10 | return completion.IsValidCompletionStartsWithIgnoreCase(partial) || completion.IsSubsequenceMatch(partial);
11 | }
12 |
13 | public static bool IsValidCompletionStartsWithExactCase(this string completion, string partial)
14 | {
15 | return completion.StartsWith(partial);
16 | }
17 |
18 | public static bool IsValidCompletionStartsWithIgnoreCase(this string completion, string partial)
19 | {
20 | return completion.ToLower().StartsWith(partial.ToLower());
21 | }
22 |
23 | public static bool IsCamelCaseMatch(this string completion, string partial)
24 |
25 | {
26 | return new string(completion.Where(c => c >= 'A' && c <= 'Z').ToArray()).StartsWith(partial.ToUpper());
27 | }
28 |
29 | public static bool IsSubsequenceMatch(this string completion, string partial)
30 | {
31 | if (partial == string.Empty)
32 | return true;
33 |
34 | var firstLetter = partial.ToLower()[0];
35 | if(!(firstLetter >= 'a' && firstLetter <= 'z'))
36 | return false;
37 | return new string(completion.ToUpper().Intersect(partial.ToUpper()).ToArray()) == partial.ToUpper();
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/OmniSharp/Build/BuildCommandModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using OmniSharp.Solution;
3 | using Nancy.ModelBinding;
4 |
5 | namespace OmniSharp.Build
6 | {
7 | public class BuildCommandModule : NancyModule
8 | {
9 | public BuildCommandModule(BuildCommandBuilder commandBuilder)
10 | {
11 | Post["BuildCommand", "/buildcommand"] = x =>
12 | Response.AsText(commandBuilder.Executable.ApplyPathReplacementsForClient() + " " + commandBuilder.BuildArguments(true));
13 |
14 | Post["BuildTarget", "/buildtarget"] = x =>
15 | {
16 | var req = this.Bind();
17 | return Response.AsJson(commandBuilder.BuildCommand(req));
18 | };
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/OmniSharp/Build/BuildLogParser.cs:
--------------------------------------------------------------------------------
1 | using System.Text.RegularExpressions;
2 | using OmniSharp.Common;
3 |
4 | namespace OmniSharp.Build
5 | {
6 | public class BuildLogParser
7 | {
8 |
9 | public QuickFix Parse(string line)
10 | {
11 | if (!line.Contains("warning CS") && !line.Contains("error CS"))
12 | return null;
13 |
14 | var match = GetMatches(line, @".*(Source file '(.*)'.*)");
15 | if(match.Matched)
16 | {
17 | var matches = match.Matches;
18 | var quickFix = new QuickFix
19 | {
20 | FileName = matches[0].Groups[2].Value,
21 | Text = matches[0].Groups[1].Value.Replace("'", "''")
22 | };
23 |
24 | return quickFix;
25 | }
26 |
27 | match = GetMatches(line, @"\s*(.*cs)\((\d+),(\d+)\).*(warning|error) CS\d+: (.*) \[");
28 | if(match.Matched)
29 | {
30 | var matches = match.Matches;
31 | var quickFix = new QuickFix
32 | {
33 | FileName = matches[0].Groups[1].Value,
34 | Line = int.Parse(matches[0].Groups[2].Value),
35 | Column = int.Parse(matches[0].Groups[3].Value),
36 | Text = "[" + matches[0].Groups[4].Value + "] " + matches[0].Groups[5].Value.Replace("'", "''")
37 | };
38 |
39 | return quickFix;
40 | }
41 | return null;
42 | }
43 |
44 | private Match GetMatches(string line, string regex)
45 | {
46 | var match = new Match();
47 | var matches = Regex.Matches(line, regex, RegexOptions.Compiled);
48 | if (matches.Count > 0 && !Regex.IsMatch(line, @"\d+>"))
49 | {
50 | match.Matched = true;
51 | match.Matches = matches;
52 | }
53 | return match;
54 | }
55 |
56 | class Match
57 | {
58 | public bool Matched { get; set; }
59 | public MatchCollection Matches { get; set; }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/OmniSharp/Build/BuildModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 |
3 | namespace OmniSharp.Build
4 | {
5 | public class BuildModule : NancyModule
6 | {
7 | public BuildModule(BuildHandler buildHandler)
8 | {
9 | Post["/build"] = x => Response.AsJson(buildHandler.Build());
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/OmniSharp/Build/BuildResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using OmniSharp.Common;
3 |
4 | namespace OmniSharp.Build
5 | {
6 | public class BuildResponse
7 | {
8 | public BuildResponse()
9 | {
10 | QuickFixes = new List();
11 | }
12 | public bool Success { get; set; }
13 | public IEnumerable QuickFixes { get; set; }
14 | }
15 | }
--------------------------------------------------------------------------------
/OmniSharp/Build/BuildTargetRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.Build
4 | {
5 | public class BuildTargetRequest : Request
6 | {
7 | public string Project { get; set; }
8 |
9 | public BuildType Type { get; set; }
10 |
11 | public BuildConfiguration Configuration { get; set; }
12 |
13 | public enum BuildType
14 | {
15 | Build,
16 | Rebuild,
17 | Clean
18 | }
19 |
20 | public enum BuildConfiguration
21 | {
22 | Debug,
23 | Release
24 | }
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/OmniSharp/Build/BuildTargetResponse.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using OmniSharp.Solution;
3 |
4 | namespace OmniSharp.Build
5 | {
6 | public class BuildTargetResponse
7 | {
8 | public string Command
9 | {
10 | get;
11 | set;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/OmniSharp/Build/Metadata/BuildCommandMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.Build.Metadata
5 | {
6 | public class BuildCommandMetadataModule : MetadataModule
7 | {
8 | public BuildCommandMetadataModule()
9 | {
10 | Describe["BuildCommand"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/buildcommand")
12 | .Response(200)
13 | .Model());
14 |
15 | Describe["BuildTarget"] = desc => desc.AsSwagger(builder => builder
16 | .ResourcePath("/buildtarget")
17 | .BodyParam()
18 | .Response(200)
19 | .Model());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/OmniSharp/CheckAliveStatus/CheckAliveStatusModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 |
3 | namespace OmniSharp.CheckAliveStatus
4 | {
5 | public class CheckAliveStatusModule : NancyModule
6 | {
7 | public CheckAliveStatusModule()
8 | {
9 | Post["CheckAliveStatus", "/checkalivestatus"] = x =>
10 | {
11 | return Response.AsJson(true);
12 | };
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/OmniSharp/CheckAliveStatus/Metadata/CheckAliveStatusMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.CheckAliveStatus.Metadata
5 | {
6 | public class CheckAliveStatusMetadataModule : MetadataModule
7 | {
8 | public CheckAliveStatusMetadataModule()
9 | {
10 | Describe["CheckAliveStatus"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/checkalivestatus")
12 | .Response(200)
13 | .Model());
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/OmniSharp/CheckReadyStatus/CheckReadyStatusModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using OmniSharp.Solution;
3 |
4 | namespace OmniSharp.CheckReadyStatus
5 | {
6 | public class CheckReadyStatusModule : NancyModule
7 | {
8 | public CheckReadyStatusModule(ISolution solution)
9 | {
10 | Post["CheckReadyStatus", "/checkreadystatus"] = x =>
11 | {
12 | return Response.AsJson(solution.Loaded);
13 | };
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/OmniSharp/CheckReadyStatus/Metadata/CheckReadyStatusMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.CheckReadyStatus.Metadata
5 | {
6 | public class CheckReadyStatusMetadataModule : MetadataModule
7 | {
8 |
9 | public CheckReadyStatusMetadataModule()
10 | {
11 | Describe["CheckReadyStatus"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/checkreadystatus")
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/CodeActionProviders.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using ICSharpCode.NRefactory.CSharp.Refactoring;
6 |
7 | namespace OmniSharp.CodeActions
8 | {
9 | public class CodeActionProviders
10 | {
11 | public IEnumerable GetProviders()
12 | {
13 | var types = Assembly.GetAssembly(typeof(UseVarKeywordAction))
14 | .GetTypes()
15 | .Where(t => typeof(CodeActionProvider).IsAssignableFrom(t));
16 |
17 | IEnumerable providers =
18 | types
19 | .Where(type => !type.IsInterface
20 | && !type.IsAbstract
21 | && !type.ContainsGenericParameters) //TODO: handle providers with generic params
22 | .Select(type => (CodeActionProvider) Activator.CreateInstance(type));
23 |
24 | return providers;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/FixUsingsModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 | using OmniSharp.CodeIssues;
4 |
5 | public class FixUsingsModule : NancyModule
6 | {
7 | public FixUsingsModule(FixUsingsHandler fixUsingsHandler)
8 | {
9 | Post["FixUsings", "/fixusings"] = x =>
10 | {
11 | var req = this.Bind();
12 | var res = fixUsingsHandler.FixUsings(req);
13 | return Response.AsJson(res);
14 | };
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/FixUsingsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using OmniSharp.Common;
3 |
4 | public class FixUsingsResponse
5 | {
6 | public FixUsingsResponse(string buffer, IEnumerable ambiguous)
7 | {
8 | Buffer = buffer;
9 | AmbiguousResults = ambiguous;
10 | }
11 |
12 | public string Buffer { get; private set; }
13 | public IEnumerable AmbiguousResults { get; private set; }
14 | }
15 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/GetCodeActionRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.CodeActions
4 | {
5 | public class CodeActionRequest : Request
6 | {
7 | public int CodeAction { get; set; }
8 | public int? SelectionStartColumn { get; set; }
9 | public int? SelectionStartLine { get; set; }
10 | public int? SelectionEndColumn { get; set; }
11 | public int? SelectionEndLine { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/GetCodeActionsHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using ICSharpCode.NRefactory.CSharp.Refactoring;
4 | using OmniSharp.Common;
5 | using OmniSharp.Configuration;
6 | using OmniSharp.Parser;
7 | using OmniSharp.Refactoring;
8 |
9 | namespace OmniSharp.CodeActions
10 | {
11 | public class GetCodeActionsHandler
12 | {
13 | readonly BufferParser _bufferParser;
14 | readonly OmniSharpConfiguration _config;
15 |
16 | public GetCodeActionsHandler(BufferParser bufferParser, OmniSharpConfiguration config)
17 | {
18 | _bufferParser = bufferParser;
19 | _config = config;
20 | }
21 |
22 | public GetCodeActionsResponse GetCodeActions(Request req)
23 | {
24 | var actions = GetContextualCodeActions(req);
25 |
26 | return new GetCodeActionsResponse { CodeActions = actions.Select(a => a.Description) };
27 | }
28 |
29 | public RunCodeActionsResponse RunCodeAction(CodeActionRequest req)
30 | {
31 | var actions = GetContextualCodeActions(req).ToList();
32 | if(req.CodeAction > actions.Count)
33 | return new RunCodeActionsResponse();
34 |
35 | var context = OmniSharpRefactoringContext.GetContext(_bufferParser, req);
36 |
37 | using (var script = new OmniSharpScript(context, _config))
38 | {
39 | CodeAction action = actions[req.CodeAction];
40 | action.Run(script);
41 | }
42 |
43 | return new RunCodeActionsResponse {Text = context.Document.Text};
44 | }
45 |
46 | private IEnumerable GetContextualCodeActions(Request req)
47 | {
48 | var refactoringContext = OmniSharpRefactoringContext.GetContext(_bufferParser, req);
49 |
50 | var actions = new List();
51 | var providers = new CodeActionProviders().GetProviders();
52 | foreach (var provider in providers)
53 | {
54 | var providerActions = provider.GetActions(refactoringContext);
55 | actions.AddRange(providerActions);
56 | }
57 | return actions;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/GetCodeActionsModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 | using Request = OmniSharp.Common.Request;
4 |
5 | namespace OmniSharp.CodeActions
6 | {
7 | public class GetCodeActionsModule : NancyModule
8 | {
9 | public GetCodeActionsModule(GetCodeActionsHandler getCodeActionsHandler)
10 | {
11 | Post["GetCodeActions", "/getcodeactions"] = x =>
12 | {
13 | var req = this.Bind();
14 | var res = getCodeActionsHandler.GetCodeActions(req);
15 | return Response.AsJson(res);
16 | };
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/GetCodeActionsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace OmniSharp.CodeActions
4 | {
5 | public class GetCodeActionsResponse
6 | {
7 | public IEnumerable CodeActions { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/Metadata/FixUsingsMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.CodeActions.Metadata
6 | {
7 | public class FixUsingsMetadataModule : MetadataModule
8 | {
9 | public FixUsingsMetadataModule()
10 | {
11 | Describe["FixUsings"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/fixusings")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/Metadata/GetCodeActionsMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.CodeActions.Metadata
5 | {
6 | public class GetCodeActionsMetadataModule : MetadataModule
7 | {
8 |
9 | public GetCodeActionsMetadataModule()
10 | {
11 | Describe["GetCodeActions"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/getcodeactions")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/Metadata/RunCodeActionMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.CodeActions.Metadata
5 | {
6 | public class RunCodeActionMetadataModule : MetadataModule
7 | {
8 | public RunCodeActionMetadataModule()
9 | {
10 | Describe["RunCodeAction"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/runcodeaction")
12 | .BodyParam()
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/RunCodeActionModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.CodeActions
5 | {
6 | public class RunCodeActionModule : NancyModule
7 | {
8 | public RunCodeActionModule(GetCodeActionsHandler codeActionsHandler)
9 | {
10 | Post["RunCodeAction", "/runcodeaction"] = x =>
11 | {
12 | var req = this.Bind();
13 | var res = codeActionsHandler.RunCodeAction(req);
14 | return Response.AsJson(res);
15 | };
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/RunCodeActionRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.CodeActions
4 | {
5 | public class RunCodeActionRequest : Request
6 | {
7 | public int CodeAction { get; set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/OmniSharp/CodeActions/RunCodeActionsResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.CodeActions
2 | {
3 | public class RunCodeActionsResponse
4 | {
5 | public string Text { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/OmniSharp/CodeFormat/CodeFormatHandler.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.NRefactory.CSharp;
2 | using OmniSharp.Configuration;
3 |
4 | namespace OmniSharp.CodeFormat
5 | {
6 | public class CodeFormatHandler
7 | {
8 | readonly OmniSharpConfiguration _config;
9 |
10 | public CodeFormatHandler(OmniSharpConfiguration config)
11 | {
12 | _config = config;
13 | }
14 | public CodeFormatResponse Format(CodeFormatRequest request)
15 | {
16 | var options = _config.TextEditorOptions;
17 | var policy = _config.CSharpFormattingOptions;
18 | var formatter = new CSharpFormatter(policy, options);
19 | formatter.FormattingMode = FormattingMode.Intrusive;
20 | var output = formatter.Format(request.Buffer);
21 | return new CodeFormatResponse(output);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/OmniSharp/CodeFormat/CodeFormatModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.CodeFormat
5 | {
6 | public class CodeFormatModule : NancyModule
7 | {
8 | public CodeFormatModule(CodeFormatHandler codeFormatHandler)
9 | {
10 | Post["CodeFormat", "/codeformat"] = x =>
11 | {
12 | var request = this.Bind();
13 | return Response.AsJson(codeFormatHandler.Format(request));
14 | };
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/CodeFormat/CodeFormatRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.CodeFormat
4 | {
5 | public class CodeFormatRequest : Request
6 | {
7 | private bool _expandTab = false;
8 |
9 | public bool ExpandTab
10 | {
11 | get { return _expandTab; }
12 | set { _expandTab = value; }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/OmniSharp/CodeFormat/CodeFormatResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.CodeFormat
2 | {
3 | public class CodeFormatResponse
4 | {
5 | public CodeFormatResponse(string buffer)
6 | {
7 | Buffer = buffer;
8 | }
9 |
10 | public string Buffer { get; private set; }
11 | }
12 | }
--------------------------------------------------------------------------------
/OmniSharp/CodeFormat/Metadata/CodeFormatMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.CodeFormat.Metadata
5 | {
6 | public class CodeFormatMetadataModule : MetadataModule
7 | {
8 | public CodeFormatMetadataModule()
9 | {
10 | Describe["CodeFormat"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/codeformat")
12 | .BodyParam()
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/CodeIssues/CodeIssueProviders.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using ICSharpCode.NRefactory.CSharp;
6 | using ICSharpCode.NRefactory.CSharp.Refactoring;
7 |
8 | namespace OmniSharp.CodeIssues
9 | {
10 | public class CodeIssueProviders
11 | {
12 | public IEnumerable GetProviders()
13 | {
14 | var types = Assembly.GetAssembly(typeof(IssueCategories))
15 | .GetTypes()
16 | .Where(t => typeof(CodeIssueProvider).IsAssignableFrom(t)
17 | && !t.IsAbstract);
18 |
19 | IEnumerable providers =
20 | types
21 | .Where(type => !type.IsInterface && !type.ContainsGenericParameters) //TODO: handle providers with generic params
22 | .Select(type => (CodeIssueProvider) Activator.CreateInstance(type));
23 |
24 | return providers;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/OmniSharp/CodeIssues/CodeIssuesModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 | using OmniSharp.CodeActions;
4 | using Request = OmniSharp.Common.Request;
5 |
6 | namespace OmniSharp.CodeIssues
7 | {
8 | public class CodeIssuesModule : NancyModule
9 | {
10 | public CodeIssuesModule(CodeIssuesHandler codeIssuesHandler)
11 | {
12 | Post["GetCodeIssues", "/getcodeissues"] = x =>
13 | {
14 | var req = this.Bind();
15 | var res = codeIssuesHandler.GetCodeIssues(req);
16 | return Response.AsJson(res);
17 | };
18 |
19 | Post["FixCodeIssue", "/fixcodeissue"] = x =>
20 | {
21 | var req = this.Bind();
22 | var res = codeIssuesHandler.FixCodeIssue(req);
23 | return Response.AsJson(res);
24 | };
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/OmniSharp/CodeIssues/GetCodeIssuesResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace OmniSharp.CodeIssues
4 | {
5 | public class GetCodeIssuesResponse
6 | {
7 | public IEnumerable CodeActions { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/OmniSharp/CodeIssues/Metadata/CodeIssuesMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.CodeActions;
4 | using OmniSharp.Common;
5 |
6 | namespace OmniSharp.CodeIssues.Metadata
7 | {
8 | public class CodeIssuesMetadataModule : MetadataModule
9 | {
10 | public CodeIssuesMetadataModule()
11 | {
12 | Describe["GetCodeIssues"] = desc => desc.AsSwagger(builder => builder
13 | .ResourcePath("/getcodeissues")
14 | .BodyParam()
15 | .Response(200)
16 | .Model());
17 |
18 | Describe["FixCodeIssue"] = desc => desc.AsSwagger(builder => builder
19 | .ResourcePath("/fixcodeissue")
20 | .BodyParam()
21 | .Response(200)
22 | .Model());
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/OmniSharp/CodeIssues/RunCodeIssuesResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.CodeIssues
2 | {
3 | public class RunCodeIssuesResponse
4 | {
5 | public string Text { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/OmniSharp/Common/CygPathWrapper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using OmniSharp.Configuration;
5 |
6 | namespace OmniSharp.Common
7 | {
8 | public class CygPathWrapper
9 | {
10 | private static IDictionary CygpathProcesses = new Dictionary();
11 | private static IDictionary> CygpathCache = new Dictionary>();
12 |
13 | public static string GetCygpath(string path, PathMode target)
14 | {
15 | string convertedPath;
16 |
17 | if (!CygpathCache.ContainsKey(target))
18 | {
19 | CygpathCache[target] = new Dictionary();
20 | }
21 |
22 | if (!CygpathCache[target].TryGetValue(path, out convertedPath))
23 | {
24 | lock (CygpathProcesses)
25 | {
26 | Process process;
27 | if (!CygpathProcesses.TryGetValue(target, out process) || process.HasExited)
28 | {
29 | var targetArgument = target == PathMode.Windows ? "-w"
30 | : target == PathMode.Unix ? "-u"
31 | : target == PathMode.Cygwin ? "-u"
32 | : string.Empty;
33 | var processStartInfo = new ProcessStartInfo("cygpath", "-f - "+targetArgument)
34 | {
35 | CreateNoWindow = true,
36 | UseShellExecute = false,
37 | RedirectStandardInput = true,
38 | RedirectStandardOutput = true,
39 | };
40 |
41 | process = CygpathProcesses[target] = Process.Start(processStartInfo);
42 | }
43 |
44 | process.StandardInput.WriteLine(path);
45 | convertedPath = process.StandardOutput.ReadLine();
46 | }
47 | }
48 |
49 | return convertedPath;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/OmniSharp/Common/Error.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.Common
2 | {
3 | public class Error
4 | {
5 | public string Message { get; set; }
6 | public int Line { get; set; }
7 | public int Column { get; set; }
8 | public int EndLine { get; set; }
9 | public int EndColumn { get; set; }
10 | public string FileName { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/OmniSharp/Common/FileSystem.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace OmniSharp.Common
4 | {
5 | public class NativeFileSystem : IFileSystem
6 | {
7 | public FileInfo GetFileInfo(string filename)
8 | {
9 | return new FileInfo(filename);
10 | }
11 |
12 | public string GetDirectoryName(string filename)
13 | {
14 | return Path.GetDirectoryName(filename);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/Common/IFileSystem.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace OmniSharp.Common
4 | {
5 | public interface IFileSystem
6 | {
7 | FileInfo GetFileInfo(string filename);
8 | string GetDirectoryName(string filename);
9 | }
10 | }
--------------------------------------------------------------------------------
/OmniSharp/Common/Metadata/QuickFixMetadataProvider.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Swagger;
2 | using Nancy.Swagger.Services;
3 |
4 | namespace OmniSharp.Common.Metadata
5 | {
6 | public class QuickFixMetadataProvider : ISwaggerModelDataProvider
7 | {
8 | public SwaggerModelData GetModelData()
9 | {
10 | return SwaggerModelData.ForType(builder =>
11 | {
12 | builder.Property(p => p.LogLevel).Enum("Warning", "Error");
13 | builder.Property(p => p.EndLine).Default(-1);
14 | builder.Property(p => p.EndColumn).Default(-1);
15 | });
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/Common/Metadata/QuickFixResponseMetadataProvider.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Swagger;
2 | using Nancy.Swagger.Services;
3 |
4 | namespace OmniSharp.Common.Metadata
5 | {
6 | public class QuickFixResponseMetadataProvider : ISwaggerModelDataProvider
7 | {
8 | public SwaggerModelData GetModelData()
9 | {
10 | return SwaggerModelData.ForType(builder => builder
11 | .Property(p => p.QuickFixes).Description("A list of quick fixes"));
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/OmniSharp/Common/Metadata/RequestMetadataProvider.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Swagger;
2 | using Nancy.Swagger.Services;
3 |
4 | namespace OmniSharp.Common.Metadata
5 | {
6 | public class RequestMetadataProvider : ISwaggerModelDataProvider
7 | {
8 | public SwaggerModelData GetModelData()
9 | {
10 | return SwaggerModelData.ForType(builder =>
11 | {
12 | builder.Property(p => p.Buffer).Required(true);
13 | builder.Property(p => p.FileName).Required(true);
14 | builder.Property(p => p.Line).Required(true);
15 | builder.Property(p => p.Column).Required(true);
16 | });
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/OmniSharp/Common/QuickFixResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace OmniSharp.Common {
4 |
5 | public class QuickFixResponse {
6 | public QuickFixResponse(IEnumerable quickFixes )
7 | {
8 | QuickFixes = quickFixes;
9 | }
10 |
11 | public QuickFixResponse()
12 | {
13 | }
14 |
15 | public IEnumerable QuickFixes { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/Common/Request.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Solution;
2 |
3 | namespace OmniSharp.Common
4 | {
5 | public class Request
6 | {
7 | private string _fileName;
8 | public int Line { get; set; }
9 | public int Column { get; set; }
10 | public string Buffer { get; set; }
11 | public string FileName
12 | {
13 | get { return _fileName; }
14 | set
15 | {
16 | _fileName = value.ApplyPathReplacementsForServer();
17 | }
18 | }
19 | }
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/OmniSharp/Configuration/PathMode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace OmniSharp.Configuration
6 | {
7 | public enum PathMode
8 | {
9 | Windows,
10 | Unix,
11 | Cygwin,
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/OmniSharp/Configuration/PathReplacement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Reflection;
4 | using System.Text.RegularExpressions;
5 |
6 | namespace OmniSharp.Configuration
7 | {
8 | public class ConfigurationLoader
9 | {
10 | private static OmniSharpConfiguration _config = new OmniSharpConfiguration();
11 | public static OmniSharpConfiguration Load()
12 | {
13 | return Load(configLocation: "", clientMode: null);
14 | }
15 |
16 | public static OmniSharpConfiguration Load(string configLocation, string clientMode)
17 | {
18 | if (string.IsNullOrEmpty(configLocation))
19 | {
20 | string executableLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
21 | configLocation = Path.Combine(executableLocation, "config.json");
22 | }
23 | var config = StripComments(File.ReadAllText(configLocation));
24 | _config = new Nancy.Json.JavaScriptSerializer().Deserialize(config);
25 | _config.ConfigFileLocation = configLocation;
26 |
27 | if (!string.IsNullOrWhiteSpace(clientMode))
28 | {
29 | _config.ClientPathMode = (PathMode)Enum.Parse(typeof(PathMode), clientMode);
30 | }
31 | if (_config.ServerPathMode == null)
32 | {
33 | _config.ServerPathMode = PlatformService.IsUnix ? PathMode.Unix : PathMode.Windows;
34 | }
35 | return _config;
36 | }
37 |
38 | private static string StripComments(string json)
39 | {
40 | const string pattern = @"/\*(?>(?:(?>[^*]+)|\*(?!/))*)\*/";
41 |
42 | return Regex.Replace(json, pattern, string.Empty, RegexOptions.Multiline);
43 | }
44 |
45 | public static OmniSharpConfiguration Config { get { return _config; }}
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/OmniSharp/Configuration/TestCommands.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.Configuration
2 | {
3 | public class TestCommands
4 | {
5 | public string All { get; set; }
6 | public string Fixture { get; set; }
7 | public string Single { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/OmniSharp/CurrentFileMembers/CurrentFileMembersAsFlatModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.CurrentFileMembers
5 | {
6 | public class CurrentFileMembersAsFlatModule : NancyModule
7 | {
8 | public CurrentFileMembersAsFlatModule
9 | (CurrentFileMembersHandler handler)
10 | {
11 |
12 | Post["CurrentFileMembersAsFlat", "/currentfilemembersasflat"] = x =>
13 | {
14 | var req = this.Bind();
15 | var members = handler.GetCurrentFileMembersAsFlat(req);
16 | return Response.AsJson(members);
17 | };
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/OmniSharp/CurrentFileMembers/CurrentFileMembersAsTreeModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.CurrentFileMembers
5 | {
6 | public class CurrentFileMembersAsTreeModule : NancyModule
7 | {
8 | public CurrentFileMembersAsTreeModule
9 | (CurrentFileMembersHandler handler)
10 | {
11 |
12 | Post["CurrentFileMembersAsTree", "/currentfilemembersastree"] = x =>
13 | {
14 | var req = this.Bind();
15 | var members = handler.GetCurrentFileMembersAsTree(req);
16 | return Response.AsJson(members);
17 | };
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/OmniSharp/CurrentFileMembers/CurrentFileMembersAsTreeResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using ICSharpCode.NRefactory.Editor;
4 | using ICSharpCode.NRefactory.TypeSystem;
5 |
6 | namespace OmniSharp.CurrentFileMembers {
7 |
8 | public class CurrentFileMembersAsTreeResponse {
9 | public CurrentFileMembersAsTreeResponse() {}
10 |
11 | public CurrentFileMembersAsTreeResponse
12 | ( IEnumerable types
13 | , IDocument document) {
14 |
15 | this.TopLevelTypeDefinitions = types
16 | .Select(tld => Node.AsTree(tld, document));
17 | }
18 |
19 | ///
20 | /// The types defined in a file. They contain their members
21 | /// in a tree structure.
22 | ///
23 | public IEnumerable TopLevelTypeDefinitions {get; set;}
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/OmniSharp/CurrentFileMembers/CurrentFileMembersRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.CurrentFileMembers
4 | {
5 | public class CurrentFileMembersRequest : Request
6 | {
7 | public bool ShowAccessModifiers { get; set; }
8 |
9 | public CurrentFileMembersRequest()
10 | {
11 | ShowAccessModifiers = true;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/OmniSharp/CurrentFileMembers/CurrentFileTopLevelTypesModule.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using Nancy;
4 | using Nancy.ModelBinding;
5 | using OmniSharp.Common;
6 |
7 | namespace OmniSharp.CurrentFileMembers {
8 |
9 | ///
10 | /// Returns the locations of only the TopLevelTypeDefinitions in
11 | /// the given file.
12 | ///
13 | public class CurrentFileTopLevelTypesModule : NancyModule {
14 | public CurrentFileTopLevelTypesModule(CurrentFileMembersHandler handler) {
15 | Post["CurrentFileTopLevelTypes", "/currentfiletopleveltypes"] = x => {
16 | var req = this.Bind();
17 | var members = handler.GetCurrentFileMembersAsTree(req);
18 |
19 | IEnumerable topLevelTypeDefinitions =
20 | members.TopLevelTypeDefinitions
21 | .Select(m => m.Location);
22 |
23 | return Response.AsJson(topLevelTypeDefinitions);
24 | };
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/OmniSharp/CurrentFileMembers/Metadata/CurrentFileMembersAsFlatMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Nancy.Metadata.Module;
3 | using Nancy.Swagger;
4 | using OmniSharp.Common;
5 |
6 | namespace OmniSharp.CurrentFileMembers.Metadata
7 | {
8 | public class CurrentFileMembersAsFlatMetadataModule : MetadataModule
9 | {
10 | public CurrentFileMembersAsFlatMetadataModule()
11 | {
12 | Describe["CurrentFileMembersAsFlat"] = desc => desc.AsSwagger(builder => builder
13 | .ResourcePath("/currentfilemembersasflat")
14 | .BodyParam()
15 | .Response(200)
16 | .Model>());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/OmniSharp/CurrentFileMembers/Metadata/CurrentFileMembersAsTreeMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.CurrentFileMembers.Metadata
5 | {
6 | public class CurrentFileMembersAsTreeMetadataModule : MetadataModule
7 | {
8 | public CurrentFileMembersAsTreeMetadataModule()
9 | {
10 | Describe["CurrentFileMembersAsTree"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/currentfilemembersastree")
12 | .BodyParam()
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/CurrentFileMembers/Metadata/CurrentFileTopLevelTypesMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Nancy.Metadata.Module;
3 | using Nancy.Swagger;
4 | using OmniSharp.Common;
5 |
6 | namespace OmniSharp.CurrentFileMembers.Metadata
7 | {
8 | public class CurrentFileTopLevelTypesMetadataModule : MetadataModule
9 | {
10 | public CurrentFileTopLevelTypesMetadataModule()
11 | {
12 | Describe["CurrentFileTopLevelTypes"] = desc => desc.AsSwagger(builder => builder
13 | .ResourcePath("/currentfiletopleveltypes")
14 | .BodyParam()
15 | .Response(200)
16 | .Model>());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/OmniSharp/CurrentFileMembers/Node.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using ICSharpCode.NRefactory.CSharp;
5 | using ICSharpCode.NRefactory.Editor;
6 | using ICSharpCode.NRefactory.TypeSystem;
7 | using OmniSharp.Common;
8 | using OmniSharp.Parser;
9 |
10 | namespace OmniSharp.CurrentFileMembers {
11 |
12 | ///
13 | /// Represents a node in an abstract syntax tree.
14 | ///
15 | public class Node {
16 | public Node() {}
17 |
18 | ///
19 | /// Initializes a new instance with no child nodes for the
20 | /// given member.
21 | ///
22 | public Node(IUnresolvedMember member, IDocument document) {
23 | this.ChildNodes = null;
24 | this.Location = QuickFix.ForNonBodyRegion(member, document);
25 |
26 | // Fields' BodyRegion does not include their name for some
27 | // reason. To prevent the field's name missing, include
28 | // the whole region for them.
29 | if (member.SymbolKind == SymbolKind.Field)
30 | this.Location.Text += member.Name;
31 | }
32 |
33 | public IEnumerable ChildNodes {get; set;}
34 | public QuickFix Location {get; set;}
35 |
36 | public static Node AsTree
37 | ( IUnresolvedTypeDefinition topLevelTypeDefinition
38 | , IDocument document) {
39 |
40 | var retval = new Node()
41 | { ChildNodes = topLevelTypeDefinition.Members
42 | .Select(m => new Node(m, document))
43 | , Location = QuickFix.ForNonBodyRegion
44 | (topLevelTypeDefinition, document)};
45 |
46 | return retval;
47 | }
48 |
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/OmniSharp/Documentation/DocumentationFetcher.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Concurrent;
2 | using ICSharpCode.NRefactory.Documentation;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 | using OmniSharp.Solution;
5 | using OmniSharp.Configuration;
6 |
7 | namespace OmniSharp.Documentation
8 | {
9 | public class DocumentationFetcher
10 | {
11 | static readonly ConcurrentDictionary _documentationCache = new ConcurrentDictionary();
12 |
13 | public string GetDocumentation(IProject project, IEntity entity, OmniSharpConfiguration config)
14 | {
15 | string idString = entity.GetIdString();
16 | string result;
17 | if (_documentationCache.TryGetValue(idString, out result))
18 | return result;
19 |
20 | DocumentationComment documentationComment = null;
21 | if (entity.Documentation != null)
22 | {
23 | // Documentation from source code
24 | documentationComment = entity.Documentation;
25 | }
26 | else
27 | {
28 | if (entity.ParentAssembly.AssemblyName != null)
29 | {
30 | IDocumentationProvider docProvider =
31 | XmlDocumentationProviderFactory.Get(project, entity.ParentAssembly.AssemblyName);
32 |
33 | if (docProvider != null)
34 | {
35 | documentationComment = docProvider.GetDocumentation(entity);
36 | }
37 | }
38 | }
39 |
40 | result = documentationComment != null
41 | ? DocumentationConverter.ConvertDocumentation(documentationComment.Xml.Text, config)
42 | : null;
43 |
44 | _documentationCache.TryAdd(idString, result);
45 | return result;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/OmniSharp/Documentation/XmlDocumentationProviderFactory.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using System.Collections.Concurrent;
3 | using ICSharpCode.NRefactory.Documentation;
4 | using ICSharpCode.NRefactory.TypeSystem;
5 | using MonoDevelop.Ide.TypeSystem;
6 | using OmniSharp.Solution;
7 |
8 | namespace OmniSharp.Documentation
9 | {
10 | public static class XmlDocumentationProviderFactory
11 | {
12 | private static readonly ConcurrentDictionary _providers =
13 | new ConcurrentDictionary();
14 |
15 |
16 | public static IDocumentationProvider Get(IProject project, string assemblyName)
17 | {
18 | if (PlatformService.IsUnix)
19 | return new MonoDocDocumentationProvider();
20 |
21 | if (_providers.ContainsKey(assemblyName))
22 | return _providers[assemblyName];
23 |
24 | string fileName = null;
25 | IUnresolvedAssembly reference = project.References.OfType().FirstOrDefault(i => i.AssemblyName.Equals(assemblyName));
26 | if (reference != null)
27 | fileName = XmlDocumentationProvider.LookupLocalizedXmlDoc(reference.Location);
28 |
29 | if (fileName != null)
30 | {
31 | var docProvider = new XmlDocumentationProvider(fileName);
32 | _providers.TryAdd(assemblyName, docProvider);
33 | return docProvider;
34 | }
35 | return null;
36 | }
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/OmniSharp/Extensions/NodeExtensions.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.NRefactory.CSharp;
2 |
3 | namespace OmniSharp.Extensions
4 | {
5 | static class NodeExtensions
6 | {
7 | public static AstNode GetIdentifier(this AstNode node)
8 | {
9 | if (node is ObjectCreateExpression)
10 | node = ((ObjectCreateExpression)node).Type;
11 |
12 | if (node is InvocationExpression)
13 | node = ((InvocationExpression)node).Target;
14 |
15 | if (node is MemberReferenceExpression)
16 | node = ((MemberReferenceExpression)node).MemberNameToken;
17 |
18 | if (node is SimpleType)
19 | node = ((SimpleType)node).IdentifierToken;
20 |
21 | if (node is MemberType)
22 | node = ((MemberType)node).MemberNameToken;
23 |
24 | if (node is TypeDeclaration)
25 | node = ((TypeDeclaration)node).NameToken;
26 | if (node is DelegateDeclaration)
27 | node = ((DelegateDeclaration)node).NameToken;
28 |
29 | if (node is EntityDeclaration)
30 | node = ((EntityDeclaration)node).NameToken;
31 |
32 | if (node is ParameterDeclaration)
33 | node = ((ParameterDeclaration)node).NameToken;
34 | if (node is ConstructorDeclaration)
35 | node = ((ConstructorDeclaration)node).NameToken;
36 | if (node is DestructorDeclaration)
37 | node = ((DestructorDeclaration)node).NameToken;
38 | if (node is NamedArgumentExpression)
39 | node = ((NamedArgumentExpression)node).NameToken;
40 | if (node is NamedExpression)
41 | node = ((NamedExpression)node).NameToken;
42 | if (node is VariableInitializer)
43 | node = ((VariableInitializer)node).NameToken;
44 |
45 | if (node is IdentifierExpression)
46 | {
47 | node = ((IdentifierExpression)node).IdentifierToken;
48 | }
49 |
50 | return node;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/OmniSharp/FindProjects/FindProjectsHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using OmniSharp.Common;
4 | using OmniSharp.Solution;
5 |
6 | namespace OmniSharp.FindProjects
7 | {
8 | public class FindProjectsHandler
9 | {
10 | readonly ISolution _solution;
11 |
12 | public FindProjectsHandler(ISolution solution)
13 | {
14 | _solution = solution;
15 | }
16 |
17 | public FindProjectsResponse FindAllProjects()
18 | {
19 | var projects = _solution.Projects
20 | .Where(x => x.Title != OrphanProject.ProjectFileName)
21 | .OrderBy(x => x.Title)
22 | .Select(t => new MsBuildProject(t));
23 | return new FindProjectsResponse { MSBuild = new MsBuildWorkspaceInformation{ Projects = projects }};
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OmniSharp/FindProjects/FindProjectsModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | namespace OmniSharp.FindProjects
3 | {
4 | public class FindProjectsModule : NancyModule
5 | {
6 | public FindProjectsModule(FindProjectsHandler handler)
7 | {
8 | Post["Projects", "/projects"] = x =>
9 | {
10 | var res = handler.FindAllProjects();
11 | return Response.AsJson(res);
12 | };
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/OmniSharp/FindProjects/FindProjectsResponse.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using OmniSharp.Solution;
4 |
5 | namespace OmniSharp.FindProjects
6 | {
7 | public class FindProjectsResponse
8 | {
9 | public MsBuildWorkspaceInformation MSBuild { get; set; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/OmniSharp/FindProjects/MsBuildProject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using OmniSharp.Solution;
3 |
4 | namespace OmniSharp.FindProjects
5 | {
6 | public class MsBuildProject
7 | {
8 | public Guid ProjectGuid { get; set; }
9 | public string Path { get; set; }
10 | public string AssemblyName { get; set; }
11 |
12 | public MsBuildProject(IProject p)
13 | {
14 | AssemblyName = p.Title;
15 | Path = p.FileName;
16 | ProjectGuid = p.ProjectId;
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/OmniSharp/FindProjects/MsBuildWorkspaceInformation.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace OmniSharp.FindProjects
4 | {
5 | public class MsBuildWorkspaceInformation
6 | {
7 | public string SolutionPath { get; set; }
8 | public IEnumerable Projects { get; set; }
9 | }
10 | }
--------------------------------------------------------------------------------
/OmniSharp/FindSymbols/FindSymbolsHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 | using OmniSharp.Common;
5 | using OmniSharp.Solution;
6 |
7 | namespace OmniSharp.FindSymbols
8 | {
9 | public class FindSymbolsHandler
10 | {
11 | private readonly ISolution _solution;
12 |
13 | public FindSymbolsHandler(ISolution solution)
14 | {
15 | _solution = solution;
16 | }
17 |
18 | ///
19 | /// Find all symbols that only exist within the solution source tree
20 | ///
21 | public QuickFixResponse FindAllSymbols()
22 | {
23 | IEnumerable types =
24 | _solution.Projects.SelectMany(
25 | project => project.ProjectContent.GetAllTypeDefinitions().SelectMany(t => t.Members));
26 |
27 | var quickfixes = types.Select(t => new QuickFix
28 | {
29 | Text = t.Name + "\t(in " + t.DeclaringTypeDefinition.FullTypeName + ")",
30 | FileName = t.UnresolvedFile.FileName,
31 | Column = t.Region.BeginColumn,
32 | Line = t.Region.BeginLine
33 | });
34 |
35 | return new QuickFixResponse(quickfixes);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/OmniSharp/FindSymbols/FindSymbolsModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 |
3 | namespace OmniSharp.FindSymbols
4 | {
5 | public class FindSymbolsModule : NancyModule
6 | {
7 | public FindSymbolsModule(FindSymbolsHandler handler)
8 | {
9 | Post["FindSymbols", "/findsymbols"] = x =>
10 | {
11 | var res = handler.FindAllSymbols();
12 | return Response.AsJson(res);
13 | };
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/OmniSharp/FindSymbols/Metadata/FindSymbolsMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.FindSymbols.Metadata
6 | {
7 | public class FindSymbolsMetadataModule : MetadataModule
8 | {
9 | public FindSymbolsMetadataModule()
10 | {
11 | Describe["FindSymbols"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/findsymbols")
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/FindTypes/FindTypesHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 | using OmniSharp.Common;
5 | using OmniSharp.Solution;
6 |
7 | namespace OmniSharp.FindTypes
8 | {
9 | public class FindTypesHandler
10 | {
11 | readonly ISolution _solution;
12 |
13 | public FindTypesHandler(ISolution solution)
14 | {
15 | _solution = solution;
16 | }
17 |
18 | ///
19 | /// Find all types that only exist within the solution source tree
20 | ///
21 | public QuickFixResponse FindAllTypes()
22 | {
23 | IEnumerable types =
24 | _solution.Projects.SelectMany(
25 | project => project.ProjectContent.GetAllTypeDefinitions());
26 |
27 | var quickfixes = types.Select(t => new QuickFix
28 | {
29 | Text = t.Name + "\t(in " + t.Namespace + ")",
30 | FileName = t.UnresolvedFile.FileName,
31 | Column = t.Region.BeginColumn,
32 | Line = t.Region.BeginLine
33 | });
34 |
35 | return new QuickFixResponse(quickfixes);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/OmniSharp/FindTypes/FindTypesModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 |
3 | namespace OmniSharp.FindTypes
4 | {
5 | public class FindTypesModule : NancyModule
6 | {
7 | public FindTypesModule(FindTypesHandler handler)
8 | {
9 | Post["FindTypes", "/findtypes"] = x =>
10 | {
11 | var res = handler.FindAllTypes();
12 | return Response.AsJson(res);
13 | };
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/OmniSharp/FindTypes/Metadata/FindTypesMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.FindTypes.Metadata
6 | {
7 | public class FindTypesMetadataModule : MetadataModule
8 | {
9 | public FindTypesMetadataModule()
10 | {
11 | Describe["FindTypes"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/findtypes")
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/FindUsages/FindUsagesModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.FindUsages
5 | {
6 | public class FindUsagesModule : NancyModule
7 | {
8 | public FindUsagesModule(FindUsagesHandler findUsagesHandler)
9 | {
10 | Post["FindUsages", "/findusages"] = x =>
11 | {
12 | var req = this.Bind();
13 | var usages = findUsagesHandler.FindUsages(req);
14 | return Response.AsJson(usages);
15 | };
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/FindUsages/FindUsagesRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.FindUsages
4 | {
5 | public class FindUsagesRequest : Request
6 | {
7 | private int _maxWidth = 100;
8 |
9 | public int MaxWidth
10 | {
11 | get { return _maxWidth; }
12 | set { _maxWidth = value; }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/OmniSharp/FindUsages/Metadata/FindUsagesMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.FindUsages.Metadata
6 | {
7 | public class FindUsagesMetadataModule : MetadataModule
8 | {
9 | public FindUsagesMetadataModule()
10 | {
11 | Describe["FindUsages"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/findusages")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/GotoDefinition/GotoDefinitionHandler.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.NRefactory;
2 | using ICSharpCode.NRefactory.CSharp.Resolver;
3 | using ICSharpCode.NRefactory.Semantics;
4 | using OmniSharp.AutoComplete;
5 | using OmniSharp.Parser;
6 | using OmniSharp.Solution;
7 |
8 | namespace OmniSharp.GotoDefinition
9 | {
10 | public class GotoDefinitionHandler
11 | {
12 | private readonly BufferParser _bufferParser;
13 |
14 | public GotoDefinitionHandler(BufferParser bufferParser)
15 | {
16 | _bufferParser = bufferParser;
17 | }
18 |
19 | public GotoDefinitionResponse GetGotoDefinitionResponse(GotoDefinitionRequest request)
20 | {
21 | var res = _bufferParser.ParsedContent(request.Buffer, request.FileName);
22 |
23 | var loc = new TextLocation(request.Line, request.Column);
24 |
25 | ResolveResult resolveResult = ResolveAtLocation.Resolve(res.Compilation, res.UnresolvedFile, res.SyntaxTree, loc);
26 | var response = new GotoDefinitionResponse();
27 | if (resolveResult != null)
28 | {
29 | var region = resolveResult.GetDefinitionRegion();
30 | response.FileName = region.FileName == null ? null : region.FileName.ApplyPathReplacementsForClient();
31 | response.Line = region.BeginLine;
32 | response.Column = region.BeginColumn;
33 | }
34 |
35 | return response;
36 | }
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/OmniSharp/GotoDefinition/GotoDefinitionModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.GotoDefinition
5 | {
6 | public class GotoDefinitionModule : NancyModule
7 | {
8 | public GotoDefinitionModule(GotoDefinitionHandler gotoDefinitionHandler)
9 | {
10 | Post["GoToDefinition", "/gotodefinition"] = x =>
11 | {
12 | var req = this.Bind();
13 | var res = gotoDefinitionHandler.GetGotoDefinitionResponse(req);
14 | return Response.AsJson(res);
15 | };
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/OmniSharp/GotoDefinition/GotoDefinitionRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.GotoDefinition
4 | {
5 | public class GotoDefinitionRequest : Request
6 | {
7 | }
8 | }
--------------------------------------------------------------------------------
/OmniSharp/GotoDefinition/GotoDefinitionResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.GotoDefinition
2 | {
3 | public class GotoDefinitionResponse
4 | {
5 | public string FileName { get; set; }
6 | public int Line { get; set; }
7 | public int Column { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/OmniSharp/GotoDefinition/Metadata/GotoDefinitionMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.GotoDefinition.Metadata
5 | {
6 | public class GotoDefinitionMetadataModule : MetadataModule
7 | {
8 | public GotoDefinitionMetadataModule()
9 | {
10 | Describe["GoToDefinition"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/gotodefinition")
12 | .Summary("Retrieve the location of the definition of the symbol at the specified location")
13 | .BodyParam(null, true)
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/GotoDefinition/Metadata/GotoDefinitionRequestMetadataProvider.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Swagger;
2 | using Nancy.Swagger.Services;
3 |
4 | namespace OmniSharp.GotoDefinition.Metadata
5 | {
6 | public class GotoDefinitionRequestMetadataProvider : ISwaggerModelDataProvider
7 | {
8 | public SwaggerModelData GetModelData()
9 | {
10 | return SwaggerModelData.ForType(builder =>
11 | {
12 | builder.Description("request");
13 | builder.Property(p => p.Buffer).Required(true);
14 | builder.Property(p => p.FileName).Required(true);
15 | builder.Property(p => p.Line).Minimum(1).Required(true);
16 | builder.Property(p => p.Column).Minimum(1).Required(true);
17 | });
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/OmniSharp/GotoDefinition/Metadata/GotoDefinitionResponseMetadataProvider.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Swagger;
2 | using Nancy.Swagger.Services;
3 |
4 | namespace OmniSharp.GotoDefinition.Metadata
5 | {
6 | public class GotoDefinitionResponseMetadataProvider : ISwaggerModelDataProvider
7 | {
8 | public SwaggerModelData GetModelData()
9 | {
10 | return SwaggerModelData.ForType(builder =>
11 | {
12 | builder.Description("Response");
13 | builder.Property(p => p.Line).Minimum(1);
14 | builder.Property(p => p.Column).Minimum(1);
15 | builder.Property(p => p.FileName);
16 | });
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/OmniSharp/GotoFile/GotoFileHandler.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 | using OmniSharp.Solution;
3 | using System.Linq;
4 |
5 | namespace OmniSharp.GotoFile
6 | {
7 | public class GotoFileHandler
8 | {
9 | readonly ISolution _solution;
10 |
11 | public GotoFileHandler(ISolution solution) {
12 | _solution = solution;
13 | }
14 |
15 | public QuickFixResponse GetSolutionFiles()
16 | {
17 | var quickFixes = _solution.Projects
18 | .SelectMany(p => p.Files)
19 | .Select(f => new QuickFix
20 | { FileName = f.FileName
21 | , Line = 1
22 | , Column = 1
23 | , Text = f.FileName});
24 | return new QuickFixResponse(quickFixes);
25 | }
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/OmniSharp/GotoFile/GotoFileModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 |
3 | namespace OmniSharp.GotoFile
4 | {
5 | public class GotoFileModule : NancyModule
6 | {
7 | public GotoFileModule(GotoFileHandler gotoFileHandler)
8 | {
9 | Post["GotoFile", "/gotofile"] = x =>
10 | {
11 | var res = gotoFileHandler.GetSolutionFiles();
12 | return Response.AsJson(res);
13 | };
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/OmniSharp/GotoFile/Metadata/GotoFileMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.GotoFile.Metadata
6 | {
7 | public class GotoFileMetadataModule : MetadataModule
8 | {
9 | public GotoFileMetadataModule()
10 | {
11 | Describe["GotoFile"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/gotofile")
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/GotoImplementation/GotoImplementationModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 | using System.Collections.Generic;
4 | using OmniSharp.Common;
5 |
6 | namespace OmniSharp.GotoImplementation
7 | {
8 | public class GotoImplementationModule : NancyModule
9 | {
10 | public GotoImplementationModule(GotoImplementationHandler handler)
11 | {
12 | Post["FindImplementations", "/findimplementations"] = x =>
13 | {
14 | var req = this.Bind();
15 | var res =
16 | handler.FindDerivedMembersAsQuickFixes(req);
17 | return Response.AsJson(res);
18 | };
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/OmniSharp/GotoImplementation/GotoImplementationRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.GotoImplementation
4 | {
5 | public class GotoImplementationRequest : Request
6 | {
7 | }
8 | }
--------------------------------------------------------------------------------
/OmniSharp/GotoImplementation/Location.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.GotoImplementation
2 | {
3 | public class Location
4 | {
5 | public string FileName { get; set; }
6 | public int Line { get; set; }
7 | public int Column { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/OmniSharp/GotoImplementation/Metadata/GotoImplementationMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.GotoImplementation.Metadata
6 | {
7 | public class GotoImplementationMetadataModule : MetadataModule
8 | {
9 | public GotoImplementationMetadataModule()
10 | {
11 | Describe["FindImplementations"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/findimplementations")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/GotoRegion/GetDirectivesAstVisitor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using ICSharpCode.NRefactory.CSharp;
3 |
4 | namespace OmniSharp.GotoRegion {
5 |
6 | public class GetDirectivesAstVisitor : DepthFirstAstVisitor {
7 | public IList Directives =
8 | new List();
9 |
10 | public override void VisitPreProcessorDirective
11 | (PreProcessorDirective preProcessorDirective) {
12 | Directives.Add(preProcessorDirective);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/OmniSharp/GotoRegion/GotoRegionHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Collections.Generic;
4 | using ICSharpCode.NRefactory.CSharp;
5 | using OmniSharp.AutoComplete;
6 | using OmniSharp.Common;
7 | using OmniSharp.Parser;
8 |
9 | namespace OmniSharp.GotoRegion {
10 |
11 | public class GotoRegionHandler {
12 | private readonly BufferParser _parser;
13 |
14 | public GotoRegionHandler(BufferParser parser) {
15 | _parser = parser;
16 | }
17 |
18 | ///
19 | /// Returns a representation of the current buffer's members
20 | /// and their locations. The caller may build a UI that lets
21 | /// the user navigate to them quickly.
22 | ///
23 | public QuickFixResponse
24 | GetFileRegions(Request request) {
25 | var context = new BufferContext(request, this._parser);
26 |
27 | var declarationCollector = new GetDirectivesAstVisitor();
28 | context.ParsedContent.SyntaxTree
29 | .AcceptVisitor(declarationCollector);
30 |
31 | var regions = declarationCollector.Directives
32 | .Where(d => d.Type == PreProcessorDirectiveType.Region
33 | || d.Type == PreProcessorDirectiveType.Endregion)
34 | .Select(d => QuickFix.ForFirstLineInRegion
35 | (d.GetRegion(), context.Document));
36 |
37 | return new QuickFixResponse(regions);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/OmniSharp/GotoRegion/GotoRegionModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.GotoRegion {
5 | public class GotoRegionModule : NancyModule {
6 | public GotoRegionModule
7 | (GotoRegionHandler handler) {
8 |
9 | Post["GotoRegion", "/gotoregion"] = x =>
10 | {
11 | var req = this.Bind();
12 | var members = handler.GetFileRegions(req);
13 | return Response.AsJson(members);
14 | };
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/GotoRegion/Metadata/GotoRegionMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.GotoRegion.Metadata
6 | {
7 | public class GotoRegionMetadataModule : MetadataModule
8 | {
9 | public GotoRegionMetadataModule()
10 | {
11 | Describe["GotoRegion"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/gotoregion")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/Logger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 |
4 | namespace OmniSharp
5 | {
6 | public enum Verbosity
7 | {
8 | Silent,
9 | Quiet,
10 | Debug,
11 | Verbose
12 | }
13 |
14 | public class Logger
15 | {
16 | Verbosity _verbosity;
17 | public Verbosity Verbosity { get { return _verbosity; } }
18 |
19 | Stopwatch _stopwatch;
20 |
21 | public Logger(Verbosity verbosity)
22 | {
23 | _verbosity = verbosity;
24 | _stopwatch = new Stopwatch();
25 | _stopwatch.Start();
26 | }
27 |
28 | public void Debug(string message)
29 | {
30 | if (_verbosity != Verbosity.Quiet)
31 | Log(message);
32 | }
33 |
34 | public void Info(string message)
35 | {
36 | if (_verbosity == Verbosity.Verbose)
37 | Log(message);
38 | }
39 |
40 | public void Info(object message)
41 | {
42 | if (_verbosity == Verbosity.Verbose)
43 | Log(message);
44 | }
45 |
46 | public void Debug(string message, params object[] arg)
47 | {
48 | if (_verbosity != Verbosity.Quiet)
49 | Log(string.Format(message, arg));
50 | }
51 |
52 | public void Error(object message)
53 | {
54 | if (_verbosity != Verbosity.Silent)
55 | {
56 | var colour = Console.ForegroundColor;
57 | Console.ForegroundColor = ConsoleColor.Red;
58 | Log(message);
59 | Console.ForegroundColor = colour;
60 | }
61 | }
62 |
63 | private void Log(object message)
64 | {
65 | Console.WriteLine(_stopwatch.ElapsedMilliseconds.ToString("00000000 ") + message);
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/OmniSharp/LookupAllTypes/LookupAllTypesHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 | using OmniSharp.Solution;
5 |
6 | namespace OmniSharp.LookupAllTypes
7 | {
8 | public class LookupAllTypesHandler
9 | {
10 | private readonly ISolution _solution;
11 |
12 | public LookupAllTypesHandler(ISolution solution)
13 | {
14 | _solution = solution;
15 | }
16 |
17 | public LookupAllTypesResponse GetLookupAllTypesResponse()
18 | {
19 | var classes = new HashSet();
20 | var interfaces = new HashSet();
21 | foreach (var project in _solution.Projects)
22 | {
23 | var types = project.References.OfType()
24 | .SelectMany(unresolvedRef => unresolvedRef.GetAllTypeDefinitions())
25 | .Union(project.ProjectContent.GetAllTypeDefinitions());
26 |
27 | foreach (var def in types)
28 | {
29 | if (def.Kind == TypeKind.Interface)
30 | {
31 | interfaces.Add(def.Name);
32 | }
33 | else
34 | {
35 | classes.Add(def.Name);
36 | }
37 | }
38 | }
39 |
40 | return new LookupAllTypesResponse
41 | {
42 | Types = GetAllTypesAsString(classes),
43 | Interfaces = GetAllTypesAsString(interfaces)
44 | };
45 | }
46 |
47 | string GetAllTypesAsString(ICollection types)
48 | {
49 | // This causes a conflict with the vim keyword 'contains'
50 | types.Remove("Contains");
51 |
52 | return types.Aggregate("", (current, type) => current + type + " ");
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/OmniSharp/LookupAllTypes/LookupAllTypesModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 |
3 | namespace OmniSharp.LookupAllTypes
4 | {
5 | public class LookupAllTypesModule : NancyModule
6 | {
7 | public LookupAllTypesModule(LookupAllTypesHandler handler)
8 | {
9 | Post["LookupAllTypes", "/lookupalltypes"] = x =>
10 | {
11 | var res = handler.GetLookupAllTypesResponse();
12 | return Response.AsJson(res);
13 | };
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/OmniSharp/LookupAllTypes/LookupAllTypesRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.LookupAllTypes
4 | {
5 | public class LookupAllTypesRequest : Request
6 | {
7 | private bool _includeTypesWithoutSource = true;
8 |
9 | public bool IncludeTypesWithoutSource
10 | {
11 | get { return _includeTypesWithoutSource; }
12 | set { _includeTypesWithoutSource = value; }
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/OmniSharp/LookupAllTypes/LookupAllTypesResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.LookupAllTypes
2 | {
3 | public class LookupAllTypesResponse
4 | {
5 | public string Types { get; set; }
6 | public string Interfaces { get; set; }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/OmniSharp/LookupAllTypes/Metadata/LookupAllTypesMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.LookupAllTypes.Metadata
5 | {
6 | public class LookupAllTypesMetadataModule : MetadataModule
7 | {
8 | public LookupAllTypesMetadataModule()
9 | {
10 | Describe["LookupAllTypes"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/lookupalltypes")
12 | .Response(200)
13 | .Model());
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/OmniSharp/Overrides/GetOverrideTargetsModule.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 | using Nancy;
3 | using Nancy.ModelBinding;
4 |
5 | namespace OmniSharp.Overrides {
6 | public class GetOverrideTargetsModule : NancyModule {
7 |
8 | public GetOverrideTargetsModule
9 | (OverrideHandler overrideHandler) {
10 |
11 | Post["GetOverrideTargets", "/getoverridetargets"] = x =>
12 | {
13 | var req = this.Bind();
14 | var completions = overrideHandler.GetOverrideTargets(req);
15 | return Response.AsJson(completions);
16 | };
17 | }
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/OmniSharp/Overrides/GetOverrideTargetsResponse.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ICSharpCode.NRefactory.CSharp.Refactoring;
3 | using ICSharpCode.NRefactory.CSharp.Resolver;
4 | using ICSharpCode.NRefactory.CSharp.TypeSystem;
5 | using ICSharpCode.NRefactory.TypeSystem;
6 |
7 | namespace OmniSharp.Overrides {
8 |
9 | public class GetOverrideTargetsResponse {
10 |
11 | public GetOverrideTargetsResponse() {}
12 |
13 | public GetOverrideTargetsResponse
14 | ( IMember m
15 | , CSharpTypeResolveContext resolveContext) {
16 | if (resolveContext == null)
17 | throw new ArgumentNullException("resolveContext");
18 |
19 | if (m == null)
20 | throw new ArgumentNullException("m");
21 |
22 | this.OverrideTargetName =
23 | GetOverrideTargetName(m, resolveContext);
24 | }
25 |
26 | ///
27 | /// A human readable signature of the member that is to be
28 | /// overridden.
29 | ///
30 | public string OverrideTargetName {get; set;}
31 |
32 | public static string GetOverrideTargetName
33 | (IMember m, CSharpTypeResolveContext resolveContext) {
34 | var builder = new TypeSystemAstBuilder
35 | (new CSharpResolver(resolveContext));
36 |
37 | return builder.ConvertEntity(m).ToString()
38 | // Builder automatically adds a trailing newline
39 | .TrimEnd(Environment.NewLine.ToCharArray());
40 | }
41 |
42 |
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/OmniSharp/Overrides/Metadata/GetOverrideTargetsMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.Overrides.Metadata
6 | {
7 | public class GetOverrideTargetsMetadataModule : MetadataModule
8 | {
9 | public GetOverrideTargetsMetadataModule()
10 | {
11 | Describe["GetOverrideTargets"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/getoverridetargets")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/Overrides/Metadata/RunOverrideTargetMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.Overrides.Metadata
5 | {
6 | public class RunOverrideTargetMetadataModule : MetadataModule
7 | {
8 | public RunOverrideTargetMetadataModule()
9 | {
10 | Describe["RunOverrideTarget"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/runoverridetarget")
12 | .BodyParam()
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/Overrides/RunOverrideTargetModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.Overrides {
5 | public class RunOverrideTargetModule : NancyModule {
6 |
7 | public RunOverrideTargetModule
8 | (OverrideHandler overrideHandler) {
9 |
10 | Post["RunOverrideTarget", "/runoverridetarget"] = x =>
11 | {
12 | var req = this.Bind();
13 | var response = overrideHandler.RunOverrideTarget(req);
14 | return Response.AsJson(response);
15 | };
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/Overrides/RunOverrideTargetRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.Overrides {
4 |
5 | public class RunOverrideTargetRequest : Request {
6 | ///
7 | /// public override bool Equals(object obj);
8 | ///
9 | public string OverrideTargetName {get; set;}
10 |
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/OmniSharp/Overrides/RunOverrideTargetResponse.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Rename;
2 |
3 | namespace OmniSharp.Overrides {
4 | public class RunOverrideTargetResponse : ModifiedFileResponse {
5 | public RunOverrideTargetResponse() {}
6 | public RunOverrideTargetResponse
7 | ( string fileName
8 | , string buffer
9 | , int line
10 | , int column)
11 | : base(fileName: fileName, buffer: buffer) {
12 | this.Line = line;
13 | this.Column = column;
14 | }
15 |
16 | public int Line {get; set;}
17 | public int Column {get; set;}
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/OmniSharp/Parser/BufferParser.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.NRefactory.CSharp.TypeSystem;
2 | using ICSharpCode.NRefactory.TypeSystem;
3 | using OmniSharp.Solution;
4 |
5 | namespace OmniSharp.Parser
6 | {
7 | public class BufferParser
8 | {
9 | private readonly ISolution _solution;
10 |
11 | public BufferParser(ISolution solution)
12 | {
13 | _solution = solution;
14 | }
15 |
16 | public ParsedResult ParsedContent(string editorText, string filename)
17 | {
18 | var project = _solution.ProjectContainingFile(filename);
19 | project.UpdateFile(filename, editorText);
20 |
21 | var syntaxTree = project.CreateParser().Parse(editorText, filename);
22 |
23 | CSharpUnresolvedFile parsedFile = syntaxTree.ToTypeSystem();
24 |
25 | var pctx = project.ProjectContent.AddOrUpdateFiles(parsedFile);
26 | project.ProjectContent = pctx;
27 |
28 | ICompilation cmp = pctx.CreateCompilation();
29 |
30 | return new ParsedResult
31 | {
32 | ProjectContent = pctx,
33 | Compilation = cmp,
34 | UnresolvedFile = parsedFile,
35 | SyntaxTree = syntaxTree
36 | };
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/OmniSharp/Parser/ParsedResult.cs:
--------------------------------------------------------------------------------
1 | using ICSharpCode.NRefactory.CSharp;
2 | using ICSharpCode.NRefactory.CSharp.TypeSystem;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 |
5 | namespace OmniSharp.Parser
6 | {
7 | public class ParsedResult
8 | {
9 | public ICompilation Compilation { get; set; }
10 | public IProjectContent ProjectContent { get; set; }
11 | public CSharpUnresolvedFile UnresolvedFile { get; set; }
12 | public SyntaxTree SyntaxTree { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/OmniSharp/Platform.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace OmniSharp
4 | {
5 | public static class PlatformService
6 | {
7 | public static bool IsUnix
8 | {
9 | get
10 | {
11 | var p = (int)Environment.OSVersion.Platform;
12 | return (p == 4) || (p == 6) || (p == 128);
13 | }
14 | }
15 |
16 | public static bool IsWindows
17 | {
18 | get { return !IsUnix; }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/OmniSharp/PlatformHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace OmniSharp
4 | {
5 | internal static class PlatformHelper
6 | {
7 | private static Lazy _isMono = new Lazy(() => Type.GetType("Mono.Runtime") != null);
8 |
9 | public static bool IsMono
10 | {
11 | get
12 | {
13 | return _isMono.Value;
14 | }
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/AddFileReferenceProcessor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Linq;
3 | using System.Xml.Linq;
4 | using OmniSharp.Solution;
5 |
6 | namespace OmniSharp.ProjectManipulation.AddReference
7 | {
8 | public class AddFileReferenceProcessor : ReferenceProcessorBase, IReferenceProcessor
9 | {
10 | public AddReferenceResponse AddReference(IProject project, string reference)
11 | {
12 | var response = new AddReferenceResponse();
13 |
14 | var projectXml = project.AsXml();
15 |
16 | var referenceNodes = GetReferenceNodes(projectXml, "Reference");
17 |
18 | var relativeReferencePath = project.FileName.GetRelativePath(reference);
19 |
20 | var referenceName = reference.Substring(reference.LastIndexOf("\\") + 1).Replace(".dll", "");
21 |
22 | var referenceAlreadyAdded = referenceNodes.Any(n => n.Attribute("Include").Value.Equals(referenceName));
23 |
24 | var fileReferenceNode = CreateReferenceNode(relativeReferencePath, referenceName);
25 |
26 | if (!referenceAlreadyAdded)
27 | {
28 | if (referenceNodes.Count > 0)
29 | {
30 | referenceNodes.First().Parent.Add(fileReferenceNode);
31 | }
32 | else
33 | {
34 | var projectItemGroup = new XElement(MsBuildNameSpace + "ItemGroup");
35 | projectItemGroup.Add(fileReferenceNode);
36 | projectXml.Element(MsBuildNameSpace + "Project").Add(projectItemGroup);
37 | }
38 |
39 | project.AddReference(reference);
40 | project.Save(projectXml);
41 |
42 | response.Message = string.Format("Reference to {0} added successfully", referenceName);
43 | }
44 | else
45 | {
46 | response.Message = "Reference already added";
47 | }
48 |
49 | return response;
50 |
51 | }
52 |
53 | XElement CreateReferenceNode(string relativeReferencePath, string referenceName)
54 | {
55 | var projectReferenceNode =
56 | new XElement(MsBuildNameSpace + "Reference",
57 | new XAttribute("Include", referenceName));
58 |
59 | projectReferenceNode.Add(
60 | new XElement(MsBuildNameSpace + "HintPath",
61 | new XText(relativeReferencePath)));
62 |
63 | return projectReferenceNode;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/AddGacReferenceProcessor.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using System.Xml.Linq;
3 | using OmniSharp.Solution;
4 |
5 | namespace OmniSharp.ProjectManipulation.AddReference
6 | {
7 | public class AddGacReferenceProcessor : ReferenceProcessorBase, IReferenceProcessor
8 | {
9 | public AddReferenceResponse AddReference(IProject project, string reference)
10 | {
11 | var response = new AddReferenceResponse();
12 |
13 | var projectXml = project.AsXml();
14 |
15 | var referenceNodes = GetReferenceNodes(projectXml, "Reference");
16 |
17 | var referenceAlreadyAdded = referenceNodes.Any(n => n.Attribute("Include").Value.Equals(reference));
18 |
19 |
20 | if (!referenceAlreadyAdded)
21 | {
22 | var fileReferenceNode = CreateReferenceNode(reference);
23 | if (referenceNodes.Count > 0)
24 | {
25 | referenceNodes.First().Parent.Add(fileReferenceNode);
26 | }
27 | else
28 | {
29 | var projectItemGroup = new XElement(MsBuildNameSpace + "ItemGroup");
30 | projectItemGroup.Add(fileReferenceNode);
31 | projectXml.Element(MsBuildNameSpace + "Project").Add(projectItemGroup);
32 | }
33 |
34 | var assemblyPath = project.FindAssembly (reference);
35 | if (assemblyPath != null)
36 | {
37 | project.AddReference (assemblyPath);
38 | project.Save (projectXml);
39 | response.Message = string.Format ("Reference to {0} added successfully", reference);
40 | }
41 | else
42 | {
43 | response.Message = "Did not find " + reference;
44 | }
45 | }
46 | else
47 | {
48 | response.Message = "Reference already added";
49 | }
50 |
51 | return response;
52 | }
53 |
54 | XElement CreateReferenceNode(string referenceName)
55 | {
56 | var projectReferenceNode =
57 | new XElement(MsBuildNameSpace + "Reference",
58 | new XAttribute("Include", referenceName));
59 |
60 | return projectReferenceNode;
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/AddReferenceHandler.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Solution;
2 |
3 | namespace OmniSharp.ProjectManipulation.AddReference
4 | {
5 | public class AddReferenceHandler
6 | {
7 | private readonly ISolution _solution;
8 | private readonly IAddReferenceProcessorFactory _addReferenceProcessorFactory;
9 |
10 | public AddReferenceHandler(ISolution solution, IAddReferenceProcessorFactory addReferenceProcessorFactory)
11 | {
12 | _solution = solution;
13 | _addReferenceProcessorFactory = addReferenceProcessorFactory;
14 | }
15 |
16 | public AddReferenceResponse AddReference(AddReferenceRequest request)
17 | {
18 | var project = _solution.ProjectContainingFile(request.FileName);
19 | var processor = _addReferenceProcessorFactory.CreateProcessorFor(request);
20 | return processor.AddReference(project, request.Reference);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/AddReferenceModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.ProjectManipulation.AddReference
5 | {
6 | public class AddReferenceModule : NancyModule
7 | {
8 | public AddReferenceModule(AddReferenceHandler handler)
9 | {
10 | Post["AddReference", "/addreference"] = x =>
11 | {
12 | var req = this.Bind();
13 | var res = handler.AddReference(req);
14 | return Response.AsJson(res);
15 | };
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/AddReferenceProcessorFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using OmniSharp.Common;
5 | using OmniSharp.Solution;
6 |
7 | namespace OmniSharp.ProjectManipulation.AddReference
8 | {
9 | public interface IAddReferenceProcessorFactory
10 | {
11 | IReferenceProcessor CreateProcessorFor(AddReferenceRequest request);
12 | }
13 |
14 | public class AddReferenceProcessorFactory : IAddReferenceProcessorFactory
15 | {
16 | private readonly ISolution _solution;
17 | private readonly IFileSystem _fileSystem;
18 | private readonly IDictionary _processors;
19 |
20 | public AddReferenceProcessorFactory(ISolution solution, IEnumerable processors, IFileSystem fileSystem)
21 | {
22 | _solution = solution;
23 | _fileSystem = fileSystem;
24 | _processors = processors.ToDictionary(k => k.GetType(), v => v);
25 | }
26 |
27 | public IReferenceProcessor CreateProcessorFor(AddReferenceRequest request)
28 | {
29 | if (IsProjectReference(request.Reference))
30 | {
31 | return _processors[typeof (AddProjectReferenceProcessor)];
32 | }
33 |
34 | if (IsFileReference(request.Reference))
35 | {
36 | return _processors[typeof (AddFileReferenceProcessor)];
37 | }
38 |
39 | return _processors[typeof (AddGacReferenceProcessor)];
40 | }
41 |
42 | private bool IsProjectReference(string referenceName)
43 | {
44 | return _solution.Projects.Any(p => p.FileName.Contains(referenceName));
45 | }
46 |
47 | private bool IsFileReference(string reference)
48 | {
49 | var fileInfo = _fileSystem.GetFileInfo(reference);
50 | return fileInfo.Exists && fileInfo.Extension.Equals(".dll", StringComparison.InvariantCultureIgnoreCase);
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/AddReferenceRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.ProjectManipulation.AddReference
4 | {
5 | public class AddReferenceRequest : Request
6 | {
7 | public string Reference { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/AddReferenceResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.ProjectManipulation.AddReference
2 | {
3 | public class AddReferenceResponse
4 | {
5 | public string Message { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/IReferenceProcessor.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Solution;
2 |
3 | namespace OmniSharp.ProjectManipulation.AddReference
4 | {
5 | public interface IReferenceProcessor
6 | {
7 | AddReferenceResponse AddReference(IProject project, string reference);
8 | }
9 | }
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/Metadata/AddReferenceMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.ProjectManipulation.AddReference.Metadata
5 | {
6 | public class AddReferenceMetadataModule : MetadataModule
7 | {
8 | public AddReferenceMetadataModule()
9 | {
10 | Describe["AddReference"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/addreference")
12 | .BodyParam()
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddReference/ReferenceProcessorBase.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Xml.Linq;
4 |
5 | namespace OmniSharp.ProjectManipulation.AddReference
6 | {
7 | public abstract class ReferenceProcessorBase
8 | {
9 | protected readonly XNamespace MsBuildNameSpace = "http://schemas.microsoft.com/developer/msbuild/2003";
10 |
11 | protected List GetReferenceNodes(XDocument project, string nodeName)
12 | {
13 | return project.Element(MsBuildNameSpace + "Project")
14 | .Elements(MsBuildNameSpace + "ItemGroup")
15 | .Elements(MsBuildNameSpace + nodeName).ToList();
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddToProject/AddToProjectModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.ProjectManipulation.AddToProject
5 | {
6 | public class AddToProjectModule : NancyModule
7 | {
8 | public AddToProjectModule(AddToProjectHandler handler)
9 | {
10 | Post["AddToProject", "/addtoproject"] = x =>
11 | {
12 | var req = this.Bind();
13 | handler.AddToProject(req);
14 | return Response.AsJson(true);
15 | };
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddToProject/AddToProjectRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.ProjectManipulation.AddToProject
4 | {
5 | public class AddToProjectRequest : Request
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/AddToProject/Metadata/AddToProjectMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.ProjectManipulation.AddToProject.Metadata
5 | {
6 | public class AddToProjectMetadataModule : MetadataModule
7 | {
8 | public AddToProjectMetadataModule()
9 | {
10 | Describe["AddToProject"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/addtoproject")
12 | .BodyParam()
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/ProjectNotFoundException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace OmniSharp.ProjectManipulation
4 | {
5 | public class ProjectNotFoundException : Exception
6 | {
7 | public ProjectNotFoundException(string message) : base(message)
8 | {
9 |
10 | }
11 |
12 | public ProjectNotFoundException(string message, Exception innerException) : base(message, innerException)
13 | {
14 |
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/RemoveFromProject/Metadata/RemoveFromProjectMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.ProjectManipulation.RemoveFromProject.Metadata
5 | {
6 | public class RemoveFromProjectMetadataModule : MetadataModule
7 | {
8 | public RemoveFromProjectMetadataModule()
9 | {
10 | Describe["RemoveFromProject"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/removefromproject")
12 | .BodyParam()
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/RemoveFromProject/RemoveFromProjectHandler.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Xml.Linq;
5 | using OmniSharp.Solution;
6 |
7 | namespace OmniSharp.ProjectManipulation.RemoveFromProject
8 | {
9 | public class RemoveFromProjectHandler
10 | {
11 | readonly ISolution _solution;
12 |
13 | public RemoveFromProjectHandler(ISolution solution)
14 | {
15 | _solution = solution;
16 | }
17 |
18 | public void RemoveFromProject(RemoveFromProjectRequest request)
19 | {
20 | var relativeProject = _solution.ProjectContainingFile(request.FileName);
21 |
22 | if (relativeProject == null || relativeProject is OrphanProject)
23 | {
24 | throw new ProjectNotFoundException(string.Format("Unable to find project relative to file {0}", request.FileName));
25 | }
26 |
27 | var project = relativeProject.AsXml();
28 | var separator = relativeProject.FileName.Contains ("/") ? "/" : "\\";
29 | var relativeFileName = request.FileName.Replace(relativeProject.FileName.Substring(0, relativeProject.FileName.LastIndexOf(separator) + 1), "")
30 | .Replace("/", @"\");
31 |
32 | var fileNode = project.CompilationNodes()
33 | .FirstOrDefault(n => n.Attribute("Include")
34 | .Value.Equals(relativeFileName, StringComparison.InvariantCultureIgnoreCase));
35 |
36 | if (fileNode != null)
37 | {
38 | RemoveFileFromProject(relativeProject, request.FileName);
39 |
40 | project.CompilationNodes().Where(n => n.Attribute("Include").Value.Equals(relativeFileName, StringComparison.InvariantCultureIgnoreCase)).Remove();
41 |
42 | var nodes = project.CompilationNodes();
43 |
44 | if (!nodes.Any())
45 | {
46 | project.ItemGroupNodes().Where(n => !n.Nodes().Any()).Remove();
47 | }
48 |
49 | relativeProject.Save(project);
50 | }
51 | }
52 |
53 | private void RemoveFileFromProject(IProject project, string filename)
54 | {
55 | project.Files.Remove(project.Files.First(f => f.FileName == filename));
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/RemoveFromProject/RemoveFromProjectModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.ProjectManipulation.RemoveFromProject
5 | {
6 | public class RemoveFromProjectModule : NancyModule
7 | {
8 | public RemoveFromProjectModule(RemoveFromProjectHandler handler)
9 | {
10 | Post["RemoveFromProject", "/removefromproject"] = x =>
11 | {
12 | var req = this.Bind();
13 | handler.RemoveFromProject(req);
14 | return Response.AsJson(true);
15 | };
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/RemoveFromProject/RemoveFromProjectRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.ProjectManipulation.RemoveFromProject
4 | {
5 | public class RemoveFromProjectRequest : Request
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/OmniSharp/ProjectManipulation/RemoveFromProject/XDocumentExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Xml.Linq;
3 |
4 | namespace OmniSharp.ProjectManipulation.RemoveFromProject
5 | {
6 | public static class XDocumentExtensions
7 | {
8 | private static readonly XNamespace _msBuildNameSpace = "http://schemas.microsoft.com/developer/msbuild/2003";
9 |
10 | public static IEnumerable ItemGroupNodes(this XDocument document)
11 | {
12 | return document.Element(_msBuildNameSpace + "Project")
13 | .Elements(_msBuildNameSpace + "ItemGroup");
14 | }
15 |
16 | public static IEnumerable CompilationNodes(this XDocument document)
17 | {
18 | return document.Element(_msBuildNameSpace + "Project")
19 | .Elements(_msBuildNameSpace + "ItemGroup")
20 | .Elements(_msBuildNameSpace + "Compile");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/OmniSharp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("OmniSharp")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("OmniSharp")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("12366b10-54ae-44f5-b22d-8e0fb2e5e420")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/OmniSharp/ReloadSolution/Metadata/ReloadSolutionMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.ReloadSolution.Metadata
5 | {
6 | public class ReloadSolutionMetadataModule : MetadataModule
7 | {
8 | public ReloadSolutionMetadataModule()
9 | {
10 | Describe["ReloadSolution"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/reloadsolution")
12 | .Response(200)
13 | .Model());
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/OmniSharp/ReloadSolution/ReloadSolutionModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using OmniSharp.Solution;
3 |
4 | namespace OmniSharp.ReloadSolution
5 | {
6 | public class ReloadSolutionModule : NancyModule
7 | {
8 | public ReloadSolutionModule(ISolution solution)
9 | {
10 | Post["ReloadSolution", "/reloadsolution"] = x =>
11 | {
12 | solution.Reload();
13 | var config = Configuration.ConfigurationLoader.Config;
14 | string mode = config.ClientPathMode.HasValue
15 | ? config.ClientPathMode.Value.ToString()
16 | : null;
17 | Configuration.ConfigurationLoader.Load(config.ConfigFileLocation, mode);
18 | return Response.AsJson(true);
19 | };
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/OmniSharp/Rename/Metadata/RenameMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.Rename.Metadata
5 | {
6 | public class RenameMetadataModule : MetadataModule
7 | {
8 | public RenameMetadataModule()
9 | {
10 | Describe["Rename"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/rename")
12 | .BodyParam()
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/Rename/ModifiedFileResponse.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Solution;
2 |
3 | namespace OmniSharp.Rename
4 | {
5 | public class ModifiedFileResponse
6 | {
7 | private string _fileName;
8 | public ModifiedFileResponse() {}
9 |
10 | public ModifiedFileResponse(string fileName, string buffer) {
11 | this.FileName = fileName;
12 | this.Buffer = buffer;
13 | }
14 |
15 | public string FileName
16 | {
17 | get { return _fileName; }
18 | set
19 | {
20 | _fileName = value.ApplyPathReplacementsForClient();
21 | }
22 | }
23 | public string Buffer { get; set; }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/OmniSharp/Rename/RenameModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.Rename
5 | {
6 | public class RenameModule : NancyModule
7 | {
8 | public RenameModule(RenameHandler renameHandler)
9 | {
10 | Post["Rename", "/rename"] = x =>
11 | {
12 | var req = this.Bind();
13 | var usages = renameHandler.Rename(req);
14 | return Response.AsJson(usages);
15 | };
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/Rename/RenameRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.Rename
4 | {
5 | public class RenameRequest : Request
6 | {
7 | public string RenameTo { get; set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/OmniSharp/Rename/RenameResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace OmniSharp.Rename
4 | {
5 | public class RenameResponse
6 | {
7 | public RenameResponse()
8 | {
9 | Changes = new List();
10 | }
11 | public IEnumerable Changes { get; set; }
12 | }
13 | }
--------------------------------------------------------------------------------
/OmniSharp/SemanticErrors/Metadata/SemanticErrorsMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.SemanticErrors.Metadata
6 | {
7 | public class SemanticErrorsMetadataModule : MetadataModule
8 | {
9 | public SemanticErrorsMetadataModule()
10 | {
11 | Describe["SemanticErrors"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/semanticerrors")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/SemanticErrors/SemanticErrorsModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 | using Request = OmniSharp.Common.Request;
4 |
5 | namespace OmniSharp.SemanticErrors
6 | {
7 | public class SemanticErrorsModule : NancyModule
8 | {
9 | public SemanticErrorsModule(SemanticErrorsHandler semanticErrorsHandler)
10 | {
11 | Post["SemanticErrors", "/semanticerrors"] = x =>
12 | {
13 | var req = this.Bind();
14 | var res = semanticErrorsHandler.FindSemanticErrors(req);
15 | return Response.AsJson(res);
16 | };
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/OmniSharp/SemanticErrors/SemanticErrorsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using OmniSharp.Common;
3 |
4 | namespace OmniSharp.SemanticErrors
5 | {
6 | public class SemanticErrorsResponse
7 | {
8 | public IEnumerable Errors { get; set; }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/OmniSharp/Solution/CSharpFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using ICSharpCode.NRefactory.CSharp;
4 | using ICSharpCode.NRefactory.Editor;
5 | using ICSharpCode.NRefactory.TypeSystem;
6 |
7 | namespace OmniSharp.Solution
8 | {
9 | public class CSharpFile
10 | {
11 | public string FileName;
12 |
13 | public ITextSource Content;
14 | public SyntaxTree SyntaxTree;
15 | public IUnresolvedFile ParsedFile;
16 |
17 |
18 | public StringBuilderDocument Document { get; set; }
19 |
20 | public CSharpFile(IProject project, string fileName) : this(project, fileName, File.ReadAllText(fileName))
21 | {
22 | }
23 |
24 | public CSharpFile(IProject project, string fileName, string source)
25 | {
26 | Parse(project, fileName, source);
27 | }
28 |
29 | public void Parse(IProject project, string fileName, string source)
30 | {
31 | this.FileName = fileName;
32 | this.Content = new StringTextSource(source);
33 | this.Document = new StringBuilderDocument(this.Content);
34 | this.Project = project;
35 | CSharpParser p = project.CreateParser();
36 | this.SyntaxTree = p.Parse(Content.CreateReader(), fileName);
37 | this.ParsedFile = this.SyntaxTree.ToTypeSystem();
38 | }
39 |
40 | protected IProject Project { get; set; }
41 |
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/OmniSharp/Solution/CSharpFolder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO.Abstractions;
4 | using System.Linq;
5 |
6 | namespace OmniSharp.Solution
7 | {
8 | public class CSharpFolder : ISolution
9 | {
10 | Logger _logger;
11 | CSharpProject _project;
12 | IFileSystem _fileSystem;
13 |
14 | public CSharpFolder(string folder, Logger logger, IFileSystem fileSystem)
15 | {
16 | _logger = logger;
17 | FileName = folder;
18 | _fileSystem = fileSystem;
19 | }
20 |
21 | public string FileName { get; private set; }
22 | public bool Terminated { get; private set; }
23 | public bool Loaded { get; private set; }
24 |
25 | public void LoadSolution()
26 | {
27 | Loaded = false;
28 | _project = new CSharpProject(this, _logger, FileName, _fileSystem);
29 | Loaded = true;
30 | }
31 |
32 | public CSharpFile GetFile(string filename)
33 | {
34 | return (from file in _project.Files
35 | where file.FileName.Equals(filename, StringComparison.InvariantCultureIgnoreCase)
36 | select file).FirstOrDefault();
37 | }
38 |
39 | public IProject ProjectContainingFile(string filename)
40 | {
41 | return _project;
42 | }
43 |
44 | public void Reload()
45 | {
46 | LoadSolution();
47 | }
48 |
49 | public void Terminate()
50 | {
51 | Terminated = true;
52 | }
53 |
54 | public List Projects
55 | {
56 | get
57 | {
58 | return new List { _project };
59 | }
60 | }
61 |
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/OmniSharp/Solution/IProject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Xml.Linq;
4 | using ICSharpCode.NRefactory.CSharp;
5 | using ICSharpCode.NRefactory.TypeSystem;
6 |
7 | namespace OmniSharp.Solution
8 | {
9 | public interface IProject
10 | {
11 | IProjectContent ProjectContent { get; set; }
12 | string Title { get; set; }
13 | string FileName { get; }
14 | List Files { get; }
15 | List References { get; set; }
16 | void UpdateFile (string filename, string source);
17 | CSharpParser CreateParser();
18 | XDocument AsXml();
19 | void Save(XDocument project);
20 | Guid ProjectId { get; set; }
21 | void AddReference(IAssemblyReference reference);
22 | void AddReference(string reference);
23 | CompilerSettings CompilerSettings { get; }
24 | string FindAssembly (string evaluatedInclude);
25 | }
26 | }
--------------------------------------------------------------------------------
/OmniSharp/Solution/OrphanProject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO.Abstractions;
4 | using ICSharpCode.NRefactory.CSharp;
5 | using ICSharpCode.NRefactory.TypeSystem;
6 | using System.Linq;
7 |
8 | namespace OmniSharp.Solution
9 | {
10 | ///
11 | /// Placeholder that can be used for files that don't belong to a project yet.
12 | ///
13 | public class OrphanProject : Project
14 | {
15 | public const string ProjectFileName = "OrphanProject";
16 | public OrphanProject(IFileSystem fileSystem, Logger logger) : base(fileSystem, logger)
17 | {
18 | Title = "Orphan Project";
19 | Files = new List();
20 |
21 | ProjectId = Guid.NewGuid();
22 |
23 | References = new List();
24 | FileName = ProjectFileName;
25 | string mscorlib = FindAssembly("mscorlib");
26 | Console.WriteLine(mscorlib);
27 | ProjectContent = new CSharpProjectContent()
28 | .SetAssemblyName(ProjectFileName)
29 | .AddAssemblyReferences(LoadAssembly(mscorlib));
30 | }
31 |
32 | private CSharpFile GetFile(string fileName, string source)
33 | {
34 | var file = Files.FirstOrDefault(f => f.FileName.Equals(fileName, StringComparison.InvariantCultureIgnoreCase));
35 | if (file == null)
36 | {
37 | file = new CSharpFile(this, fileName, source);
38 | Files.Add (file);
39 |
40 | this.ProjectContent = this.ProjectContent
41 | .AddOrUpdateFiles(file.ParsedFile);
42 | }
43 | return file;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/OmniSharp/Solution/ProjectFinder.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 |
5 | namespace OmniSharp.Solution
6 | {
7 | public class ProjectFinder
8 | {
9 | readonly ISolution _solution;
10 |
11 | public ProjectFinder(ISolution solution)
12 | {
13 | _solution = solution;
14 | }
15 |
16 | public IEnumerable FindProjectsReferencing(ITypeResolveContext context)
17 | {
18 | var contextAssemblyName = context.Compilation.MainAssembly.FullAssemblyName;
19 | System.Console.WriteLine(contextAssemblyName);
20 |
21 | IProject sourceProject = _solution.Projects.FirstOrDefault(p => p.ProjectContent.FullAssemblyName == contextAssemblyName);
22 | var projectsThatReferenceUsage = from p in _solution.Projects
23 | where p.References.Any(r => r.Resolve(context).FullAssemblyName == contextAssemblyName) || p == sourceProject
24 | select p;
25 | return projectsThatReferenceUsage;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/OmniSharp/Solution/ProjectReference.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using ICSharpCode.NRefactory.TypeSystem;
4 |
5 | namespace OmniSharp.Solution
6 | {
7 | public class ProjectReference : IAssemblyReference
8 | {
9 | readonly ISolution _solution;
10 | readonly string _projectTitle;
11 | readonly Guid _projectGuid;
12 |
13 | public ProjectReference(ISolution solution, string projectTitle, Guid projectGuid)
14 | {
15 |
16 | _solution = solution;
17 | _projectTitle = projectTitle;
18 | _projectGuid = projectGuid;
19 | }
20 |
21 | public string ProjectTitle { get { return _projectTitle; } }
22 | public Guid ProjectGuid { get { return _projectGuid; } }
23 |
24 | public IAssembly Resolve(ITypeResolveContext context)
25 | {
26 | var project = _solution.Projects.FirstOrDefault(p => p.ProjectId == _projectGuid);
27 | if (project != null)
28 | return project.ProjectContent.Resolve(context);
29 | return null;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/OmniSharp/Solution/SolutionPicker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using OmniSharp.Solution;
3 | using System.IO.Abstractions;
4 |
5 | namespace OmniSharp
6 | {
7 | public class SolutionPicker
8 | {
9 | readonly IFileSystem _fileSystem;
10 |
11 | public SolutionPicker(IFileSystem fileSystem)
12 | {
13 | _fileSystem = fileSystem;
14 | }
15 |
16 | public ISolution LoadSolution(string solutionPath, Logger logger)
17 | {
18 | solutionPath = solutionPath.ApplyPathReplacementsForServer ();
19 | if (_fileSystem.Directory.Exists (solutionPath))
20 | {
21 | var unitySolutions = GetUnitySolutions(solutionPath);
22 | if (unitySolutions.Length == 1)
23 | {
24 | solutionPath = unitySolutions[0];
25 | logger.Debug ("Found solution file - " + solutionPath);
26 | return new CSharpSolution (_fileSystem, solutionPath, logger);
27 | }
28 |
29 | var slnFiles = _fileSystem.Directory.GetFiles (solutionPath, "*.sln");
30 | if (slnFiles.Length == 1)
31 | {
32 | solutionPath = slnFiles [0];
33 | logger.Debug ("Found solution file - " + solutionPath);
34 | return new CSharpSolution (_fileSystem, solutionPath, logger);
35 | }
36 | return new CSharpFolder (solutionPath, logger, _fileSystem);
37 | }
38 | return new CSharpSolution (_fileSystem, solutionPath, logger);
39 | }
40 |
41 | string[] GetUnitySolutions(string solutionPath)
42 | {
43 | return _fileSystem.Directory.GetFiles(solutionPath, "*-csharp.sln");
44 | }
45 | }
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/OmniSharp/StopServer/Metadata/StopServerMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.StopServer.Metadata
5 | {
6 | public class StopServerMetadataModule : MetadataModule
7 | {
8 | public StopServerMetadataModule()
9 | {
10 | Describe["StopServer"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/stopserver")
12 | .Response(200)
13 | .Model());
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/OmniSharp/StopServer/StopServerModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using OmniSharp.Solution;
3 |
4 | namespace OmniSharp.StopServer
5 | {
6 | public class StopServerModule : NancyModule
7 | {
8 | public StopServerModule(ISolution solution)
9 | {
10 | Post["StopServer", "/stopserver"] = x =>
11 | {
12 | solution.Terminate();
13 | return Response.AsJson(true);
14 | };
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/SyntaxErrors/CodeCheckHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using OmniSharp.CodeIssues;
4 | using OmniSharp.Common;
5 | using OmniSharp.SemanticErrors;
6 |
7 | namespace OmniSharp.SyntaxErrors
8 | {
9 | public class CodeCheckHandler
10 | {
11 | readonly SyntaxErrorsHandler _syntaxErrorsHandler;
12 | readonly CodeIssuesHandler _codeIssuesHandler;
13 | readonly SemanticErrorsHandler _semanticErrorsHandler;
14 |
15 | public CodeCheckHandler(SyntaxErrorsHandler syntaxErrorsHandler, CodeIssuesHandler codeIssuesHandler, SemanticErrorsHandler semanticErrorsHandler)
16 | {
17 | _semanticErrorsHandler = semanticErrorsHandler;
18 | _codeIssuesHandler = codeIssuesHandler;
19 | _syntaxErrorsHandler = syntaxErrorsHandler;
20 | }
21 |
22 | public IEnumerable CodeCheck(Request request)
23 | {
24 | var errors = new List();
25 |
26 | var syntaxErrors =
27 | _syntaxErrorsHandler.FindSyntaxErrors(request)
28 | .Errors.Select(
29 | x => new QuickFix {
30 | FileName = x.FileName,
31 | Column = x.Column,
32 | Line = x.Line,
33 | EndColumn = x.EndColumn,
34 | EndLine = x.EndLine,
35 | Text = x.Message,
36 | LogLevel = "Error"});
37 |
38 | errors.AddRange(syntaxErrors);
39 |
40 | if (errors.Any())
41 | {
42 | return errors;
43 | }
44 |
45 | var semanticErrors =
46 | _semanticErrorsHandler.FindSemanticErrors(request)
47 | .Errors.Select(
48 | x => new QuickFix {
49 | Column = x.Column,
50 | FileName = x.FileName,
51 | Line = x.Line,
52 | Text = x.Message ,
53 | LogLevel = "Error"});
54 |
55 | errors.AddRange(semanticErrors);
56 |
57 | if (errors.Any())
58 | {
59 | return errors;
60 | }
61 |
62 | var codeErrors = _codeIssuesHandler.GetCodeIssues(request).QuickFixes;
63 | errors.AddRange(codeErrors);
64 |
65 | return errors;
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/OmniSharp/SyntaxErrors/CodeCheckModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 | using OmniSharp.Common;
4 | using Request = OmniSharp.Common.Request;
5 |
6 | namespace OmniSharp.SyntaxErrors
7 | {
8 | public class CodeCheckModule : NancyModule
9 | {
10 | public CodeCheckModule(CodeCheckHandler handler)
11 | {
12 | Post["CodeCheck", "/codecheck"] = x =>
13 | {
14 | var req = this.Bind();
15 | var res = handler.CodeCheck(req);
16 | return Response.AsJson(new QuickFixResponse(res));
17 | };
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/OmniSharp/SyntaxErrors/Metadata/CodeCheckMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.SyntaxErrors.Metadata
6 | {
7 | public class CodeCheckMetadataModule : MetadataModule
8 | {
9 | public CodeCheckMetadataModule()
10 | {
11 | Describe["CodeCheck"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/codecheck")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/SyntaxErrors/Metadata/SyntaxErrorsMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.SyntaxErrors.Metadata
6 | {
7 | public class SyntaxErrorsMetadataModule : MetadataModule
8 | {
9 | public SyntaxErrorsMetadataModule()
10 | {
11 | Describe["SyntaxErrors"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/syntaxerrors")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/SyntaxErrors/SyntaxErrorsHandler.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using ICSharpCode.NRefactory.CSharp;
3 | using OmniSharp.Common;
4 | using OmniSharp.Solution;
5 | using OmniSharp.Parser;
6 | using OmniSharp.Configuration;
7 |
8 | namespace OmniSharp.SyntaxErrors
9 | {
10 | public class SyntaxErrorsHandler
11 | {
12 | private readonly ISolution _solution;
13 | public SyntaxErrorsHandler(ISolution solution)
14 | {
15 | _solution = solution;
16 | }
17 |
18 | public SyntaxErrorsResponse FindSyntaxErrors(Request request)
19 | {
20 | var parser = new CSharpParser ();
21 | var project = _solution.ProjectContainingFile(request.FileName);
22 | if (project.CompilerSettings != null) {
23 | parser.CompilerSettings = project.CompilerSettings;
24 | }
25 | var syntaxTree = parser.Parse(request.Buffer, request.FileName);
26 |
27 | var filename = request.FileName.ApplyPathReplacementsForClient();
28 |
29 | var errors = syntaxTree.Errors.Select(error => new Error
30 | {
31 | Message = error.Message.Replace("'", "''"),
32 | Column = error.Region.BeginColumn,
33 | Line = error.Region.BeginLine,
34 | EndColumn = error.Region.EndColumn,
35 | EndLine = error.Region.EndLine,
36 | FileName = filename
37 | });
38 |
39 | return new SyntaxErrorsResponse {Errors = errors};
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/OmniSharp/SyntaxErrors/SyntaxErrorsModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 | using Request = OmniSharp.Common.Request;
4 |
5 | namespace OmniSharp.SyntaxErrors
6 | {
7 | public class SyntaxErrorsModule : NancyModule
8 | {
9 | public SyntaxErrorsModule(SyntaxErrorsHandler handler)
10 | {
11 | Post["SyntaxErrors", "/syntaxerrors"] = x =>
12 | {
13 | var req = this.Bind();
14 | var res = handler.FindSyntaxErrors(req);
15 | return Response.AsJson(res);
16 | };
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/OmniSharp/SyntaxErrors/SyntaxErrorsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using OmniSharp.Common;
3 |
4 | namespace OmniSharp.SyntaxErrors
5 | {
6 | public class SyntaxErrorsResponse
7 | {
8 | public IEnumerable Errors { get; set; }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/OmniSharp/TestContextInformation/GetContextResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.TestContextInformation
2 | {
3 | public class GetContextResponse
4 | {
5 | public string AssemblyName { get; set; }
6 | public string TypeName { get; set; }
7 | public string MethodName { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/OmniSharp/TestContextInformation/GetTestContextModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.TestContextInformation
5 | {
6 | public class GetTestContextModule : NancyModule
7 | {
8 | public GetTestContextModule(GetTestContextHandler handler)
9 | {
10 | Post["/gettestcontext"] = x =>
11 | {
12 | var request = this.Bind();
13 | return Response.AsJson(handler.GetTestContextResponse(request));
14 | };
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/OmniSharp/TestContextInformation/GetTestContextResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.TestContextInformation
2 | {
3 | public class GetTestContextResponse
4 | {
5 | public string TestCommand { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/OmniSharp/TestContextInformation/TestCommandRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.TestContextInformation
4 | {
5 | public class TestCommandRequest : Request
6 | {
7 | public TestCommandType Type { get; set; }
8 | public enum TestCommandType
9 | {
10 | All, Fixture, Single
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/OmniSharp/TypeLookup/Metadata/TypeLookupMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 |
4 | namespace OmniSharp.TypeLookup.Metadata
5 | {
6 | public class TypeLookupMetadataModule : MetadataModule
7 | {
8 | public TypeLookupMetadataModule()
9 | {
10 | Describe["TypeLookup"] = desc => desc.AsSwagger(builder => builder
11 | .ResourcePath("/typelookup")
12 | .BodyParam()
13 | .Response(200)
14 | .Model());
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/OmniSharp/TypeLookup/TypeLookupModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 |
4 | namespace OmniSharp.TypeLookup
5 | {
6 | public class TypeLookupModule : NancyModule
7 | {
8 | public TypeLookupModule(TypeLookupHandler typeLookupHandler)
9 | {
10 | Post["TypeLookup", "/typelookup"] = x =>
11 | {
12 | var req = this.Bind();
13 | var res = typeLookupHandler.GetTypeLookupResponse(req);
14 | return Response.AsJson(res);
15 | };
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/TypeLookup/TypeLookupRequest.cs:
--------------------------------------------------------------------------------
1 | using OmniSharp.Common;
2 |
3 | namespace OmniSharp.TypeLookup
4 | {
5 | public class TypeLookupRequest : Request
6 | {
7 | public bool IncludeDocumentation
8 | {
9 | get
10 | {
11 | return includeDocumentation;
12 | }
13 | set
14 | {
15 | includeDocumentation = value;
16 | }
17 | }
18 | bool includeDocumentation = true;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/OmniSharp/TypeLookup/TypeLookupResponse.cs:
--------------------------------------------------------------------------------
1 | namespace OmniSharp.TypeLookup
2 | {
3 | public class TypeLookupResponse
4 | {
5 | public string Type;
6 | public string Documentation;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/OmniSharp/UpdateBuffer/Metadata/UpdateBufferMetadataModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy.Metadata.Module;
2 | using Nancy.Swagger;
3 | using OmniSharp.Common;
4 |
5 | namespace OmniSharp.UpdateBuffer.Metadata
6 | {
7 | public class UpdateBufferMetadataModule : MetadataModule
8 | {
9 | public UpdateBufferMetadataModule()
10 | {
11 | Describe["UpdateBuffer"] = desc => desc.AsSwagger(builder => builder
12 | .ResourcePath("/updatebuffer")
13 | .BodyParam()
14 | .Response(200)
15 | .Model());
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/OmniSharp/UpdateBuffer/UpdateBufferModule.cs:
--------------------------------------------------------------------------------
1 | using Nancy;
2 | using Nancy.ModelBinding;
3 | using OmniSharp.Parser;
4 |
5 | namespace OmniSharp.UpdateBuffer
6 | {
7 | ///
8 | /// Used to update OmniSharp's view of a buffer
9 | ///
10 | public class UpdateBufferModule : NancyModule
11 | {
12 | public UpdateBufferModule(BufferParser bufferParser)
13 | {
14 | Post["UpdateBuffer", "/updatebuffer"] = x =>
15 | {
16 | var req = this.Bind();
17 | bufferParser.ParsedContent(req.Buffer, req.FileName);
18 | return Response.AsJson(true);
19 | };
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/OmniSharp/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/OmniSharp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/omnisharp.sublime-project:
--------------------------------------------------------------------------------
1 | {
2 | "folders":
3 | [
4 | {
5 | "name": "OmniSharp",
6 | "follow_symlinks": true,
7 | "path": ".",
8 | "file_exclude_patterns":
9 | [
10 | "*.meta",
11 | "*.png",
12 | "*.dll",
13 | "*.mdb"
14 | ],
15 | "folder_exclude_patterns":
16 | [
17 | "Library"
18 | ]
19 | }
20 | ],
21 | "settings":
22 | {
23 | "tab_size": 4
24 | },
25 | "solution_file": "./OmniSharp.sln"
26 | }
--------------------------------------------------------------------------------
/packages/CsQuery.1.3.4/CsQuery.1.3.4.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/CsQuery.1.3.4/CsQuery.1.3.4.nupkg
--------------------------------------------------------------------------------
/packages/CsQuery.1.3.4/lib/net40/CsQuery.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/CsQuery.1.3.4/lib/net40/CsQuery.dll
--------------------------------------------------------------------------------
/packages/NUnit.2.6.3/NUnit.2.6.3.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/NUnit.2.6.3/NUnit.2.6.3.nupkg
--------------------------------------------------------------------------------
/packages/NUnit.2.6.3/lib/nunit.framework.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/NUnit.2.6.3/lib/nunit.framework.dll
--------------------------------------------------------------------------------
/packages/NUnit.2.6.3/license.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/NUnit.2.6.3/license.txt
--------------------------------------------------------------------------------
/packages/Nancy.0.23.2/Nancy.0.23.2.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.0.23.2/Nancy.0.23.2.nupkg
--------------------------------------------------------------------------------
/packages/Nancy.0.23.2/lib/net40/Nancy.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.0.23.2/lib/net40/Nancy.dll
--------------------------------------------------------------------------------
/packages/Nancy.Authentication.Forms.0.23.2/Nancy.Authentication.Forms.0.23.2.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.Authentication.Forms.0.23.2/Nancy.Authentication.Forms.0.23.2.nupkg
--------------------------------------------------------------------------------
/packages/Nancy.Authentication.Forms.0.23.2/lib/net40/Nancy.Authentication.Forms.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.Authentication.Forms.0.23.2/lib/net40/Nancy.Authentication.Forms.dll
--------------------------------------------------------------------------------
/packages/Nancy.Hosting.Self.0.23.2/Nancy.Hosting.Self.0.23.2.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.Hosting.Self.0.23.2/Nancy.Hosting.Self.0.23.2.nupkg
--------------------------------------------------------------------------------
/packages/Nancy.Hosting.Self.0.23.2/lib/net40/Nancy.Hosting.Self.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.Hosting.Self.0.23.2/lib/net40/Nancy.Hosting.Self.dll
--------------------------------------------------------------------------------
/packages/Nancy.MetaData.0.23.2/Nancy.MetaData.0.23.2.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.MetaData.0.23.2/Nancy.MetaData.0.23.2.nupkg
--------------------------------------------------------------------------------
/packages/Nancy.MetaData.0.23.2/lib/net40/Nancy.Metadata.Module.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.MetaData.0.23.2/lib/net40/Nancy.Metadata.Module.dll
--------------------------------------------------------------------------------
/packages/Nancy.Swagger.0.1.0-alpha3/Nancy.Swagger.0.1.0-alpha3.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.Swagger.0.1.0-alpha3/Nancy.Swagger.0.1.0-alpha3.nupkg
--------------------------------------------------------------------------------
/packages/Nancy.Swagger.0.1.0-alpha3/lib/net40/Nancy.Swagger.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.Swagger.0.1.0-alpha3/lib/net40/Nancy.Swagger.dll
--------------------------------------------------------------------------------
/packages/Nancy.Testing.0.23.2/Nancy.Testing.0.23.2.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.Testing.0.23.2/Nancy.Testing.0.23.2.nupkg
--------------------------------------------------------------------------------
/packages/Nancy.Testing.0.23.2/lib/net40/Nancy.Testing.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Nancy.Testing.0.23.2/lib/net40/Nancy.Testing.dll
--------------------------------------------------------------------------------
/packages/Should.1.1.20/Should.1.1.20.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Should.1.1.20/Should.1.1.20.nupkg
--------------------------------------------------------------------------------
/packages/Should.1.1.20/lib/Should.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Should.1.1.20/lib/Should.dll
--------------------------------------------------------------------------------
/packages/Swagger.ObjectModel.0.1.0-alpha3/Swagger.ObjectModel.0.1.0-alpha3.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Swagger.ObjectModel.0.1.0-alpha3/Swagger.ObjectModel.0.1.0-alpha3.nupkg
--------------------------------------------------------------------------------
/packages/Swagger.ObjectModel.0.1.0-alpha3/lib/net40/Swagger.ObjectModel.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/Swagger.ObjectModel.0.1.0-alpha3/lib/net40/Swagger.ObjectModel.dll
--------------------------------------------------------------------------------
/packages/System.IO.Abstractions.1.4.0.92/System.IO.Abstractions.1.4.0.92.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/System.IO.Abstractions.1.4.0.92/System.IO.Abstractions.1.4.0.92.nupkg
--------------------------------------------------------------------------------
/packages/System.IO.Abstractions.1.4.0.92/lib/net35/System.IO.Abstractions.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/System.IO.Abstractions.1.4.0.92/lib/net35/System.IO.Abstractions.dll
--------------------------------------------------------------------------------
/packages/System.IO.Abstractions.TestingHelpers.1.4.0.92/System.IO.Abstractions.TestingHelpers.1.4.0.92.nupkg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/System.IO.Abstractions.TestingHelpers.1.4.0.92/System.IO.Abstractions.TestingHelpers.1.4.0.92.nupkg
--------------------------------------------------------------------------------
/packages/System.IO.Abstractions.TestingHelpers.1.4.0.92/lib/net35/System.IO.Abstractions.TestingHelpers.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/System.IO.Abstractions.TestingHelpers.1.4.0.92/lib/net35/System.IO.Abstractions.TestingHelpers.dll
--------------------------------------------------------------------------------
/packages/monodoc.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OmniSharp/omnisharp-server/032e744c2a5ad44d377b53c355582bf7cb34c6fd/packages/monodoc.dll
--------------------------------------------------------------------------------
/packages/repositories.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------