-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'liveshare' of https://github.com/srivatsn/PTVS into liv…
…eshare
- Loading branch information
Showing
7 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Choose> | ||
<When Condition=" '$(VisualStudioVersion)'=='15.0' Or '$(TargetVisualStudioVersion)'=='VS150' "> | ||
<PropertyGroup> | ||
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion> | ||
<FileUpgradeFlags> | ||
</FileUpgradeFlags> | ||
<UpgradeBackupLocation> | ||
</UpgradeBackupLocation> | ||
<OldToolsVersion>14.0</OldToolsVersion> | ||
</PropertyGroup> | ||
</When> | ||
<When Condition=" '$(VisualStudioVersion)'=='16.0' Or '$(TargetVisualStudioVersion)'=='VS160' "> | ||
<PropertyGroup> | ||
<MinimumVisualStudioVersion>16.0</MinimumVisualStudioVersion> | ||
<FileUpgradeFlags> | ||
</FileUpgradeFlags> | ||
<UpgradeBackupLocation> | ||
</UpgradeBackupLocation> | ||
<OldToolsVersion>16.0</OldToolsVersion> | ||
</PropertyGroup> | ||
</When> | ||
</Choose> | ||
<Import Project="..\ProjectBefore.settings" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{60DC8134-EBA5-43B8-BCC9-BB4BC16C2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Microsoft</RootNamespace> | ||
<AssemblyName>Microsoft.PythonTools.LiveShare</AssemblyName> | ||
<ProjectGuid>{4065A3C8-0E5E-42AC-9D94-509AA90C90E9}</ProjectGuid> | ||
<UseVSSDK>true</UseVSSDK> | ||
<CreateVsixContainer>true</CreateVsixContainer> | ||
<GeneratePkgDefFile>false</GeneratePkgDefFile> | ||
<CopyVsixManifestToOutput>true</CopyVsixManifestToOutput> | ||
<DeployExtension>true</DeployExtension> | ||
<DefineConstants>$(DefineConstants);$(SignedSym)</DefineConstants> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.VisualStudio.LanguageServer.Protocol, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Collections.Immutable" /> | ||
<Reference Include="System.ComponentModel.Composition" /> | ||
<Reference Include="System.Core" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Analysis\Analysis.csproj"> | ||
<Project>{a85d479d-67a9-4bdb-904a-7d86daf68a6f}</Project> | ||
<Name>Analysis</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\PythonTools\PythonTools.csproj"> | ||
<Project>{fa7be5f5-e04f-4613-b7ac-70ce10d1bb68}</Project> | ||
<Name>PythonTools</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.Cascade.LanguageServices.Common"> | ||
<HintPath>$(PackagesPath)\Microsoft.Cascade.LanguageServices.Common.0.3.536\lib\net461\Microsoft.Cascade.LanguageServices.Common.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.Cascade.Common"> | ||
<HintPath>$(PackagesPath)\Microsoft.Cascade.Common.0.3.536\lib\net461\Microsoft.Cascade.Common.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.Cascade.Client"> | ||
<HintPath>$(PackagesPath)\Microsoft.Cascade.Client.0.3.536\lib\net461\Microsoft.Cascade.Client.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.Cascade.Contracts"> | ||
<HintPath>$(PackagesPath)\Microsoft.VisualStudio.Cascade.Contracts.0.3.536\lib\net461\Microsoft.VisualStudio.Cascade.Contracts.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.Threading" /> | ||
<Reference Include="Microsoft.VisualStudio.Shell.Framework" /> | ||
<!-- <Reference Include="Microsoft.VisualStudio.Text.UI" /> --> | ||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"> | ||
<HintPath>$(PackagesPath)\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
<IncludeInVSIX>True</IncludeInVSIX> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="PythonLanguageClient.cs" /> | ||
<Compile Include="PythonLanguageClientFactory.cs" /> | ||
<Compile Include="PythonLanguageServiceProviderCallback.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="source.extension.vsixmanifest"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
<Import Project="..\ProjectAfter.settings" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
<!-- We build these assemblies into separate folders to avoid incremental cleaning issues, | ||
but then CreatePkgDef can't find them for the ProvideCodeBase attributes. So we copy | ||
into the PythonTools output folder temporarily to generate the pkgdef file. --> | ||
<!--<Target Name="_CopyForCreatePkgDef" BeforeTargets="GeneratePkgDef"> | ||
<Copy SourceFiles="$(OutputPath)..\Analysis\Microsoft.PythonTools.Analysis.dll;$(OutputPath)..\EnvironmentsList\Microsoft.PythonTools.EnvironmentsList.dll;$(OutputPath)..\VSInterpreters\Microsoft.PythonTools.VSInterpreters.dll" DestinationFolder="$(OutputPath)"> | ||
<Output TaskParameter="CopiedFiles" ItemName="_CopiedForCreatePkgdef" /> | ||
</Copy> | ||
</Target> | ||
<Target Name="_DeleteAfterCreatePkgDef" AfterTargets="GeneratePkgDef"> | ||
<Delete Files="@(_CopiedForCreatePkgdef)" /> | ||
</Target>--> | ||
<!--<Target Name="DetokenizeVsixManifestFile" />--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// <copyright> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Cascade.Extensibility; | ||
using Microsoft.Cascade.LanguageServices.Common; | ||
using Microsoft.Cascade.LanguageServices.Contracts; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Threading; | ||
using Task = System.Threading.Tasks.Task; | ||
|
||
namespace Microsoft | ||
{ | ||
internal class PythonLanguageClient : ICollaborationService, IAsyncDisposable | ||
{ | ||
private static string[] PythonContentTypes = new string[] { "python" }; | ||
private static DocumentFilter[] PythonDocumentFilters = new DocumentFilter[] | ||
{ | ||
new DocumentFilter() { Language = "python" } | ||
}; | ||
private IAsyncDisposable languageServiceProviderService; | ||
private SVsServiceProvider serviceProvider; | ||
|
||
public PythonLanguageClient(SVsServiceProvider serviceProvider) | ||
{ | ||
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
|
||
internal async Task InitializeAsync(ILanguageServerHostService languageServerHostService) | ||
{ | ||
if (languageServerHostService == null) | ||
{ | ||
throw new ArgumentNullException(nameof(languageServerHostService)); | ||
} | ||
|
||
var pythonLanguageServiceProviderCallback = new PythonLanguageServiceProviderCallback(this.serviceProvider); | ||
this.languageServiceProviderService = await languageServerHostService.CreateCustomLanguageServerProviderAsync( | ||
"languageServerProvider-python", | ||
new LanguageServerProviderMetadata | ||
{ | ||
IsLanguageClientProvider = false, | ||
ContentTypes = PythonContentTypes, | ||
DocumentFilters = PythonDocumentFilters | ||
}, | ||
pythonLanguageServiceProviderCallback, | ||
null); | ||
} | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
await this.languageServiceProviderService?.DisposeAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// <copyright> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// </copyright> | ||
|
||
using System; | ||
using System.ComponentModel.Composition; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Cascade.Client; | ||
using Microsoft.Cascade.Extensibility; | ||
using Microsoft.Cascade.LanguageServices.Common; | ||
using Microsoft.VisualStudio.Shell; | ||
|
||
namespace Microsoft | ||
{ | ||
[ExportCollaborationService( | ||
typeof(PythonLanguageClient), | ||
Scope = SessionScope.Host, | ||
Features = WellKnownFeatures.LspServices)] | ||
internal class PythonLanguageClientFactory : ICollaborationServiceFactory | ||
{ | ||
private readonly SVsServiceProvider serviceProvider; | ||
|
||
[ImportingConstructor] | ||
public PythonLanguageClientFactory(SVsServiceProvider serviceProvider) | ||
{ | ||
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
|
||
public async Task<ICollaborationService> CreateServiceAsync(SessionContext sessionContext, CancellationToken cancellationToken) | ||
{ | ||
var languageServerHostService = sessionContext.ServiceProvider.GetService<ILanguageServerHostService>(); | ||
if (languageServerHostService == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var pythonClient = new PythonLanguageClient(this.serviceProvider); | ||
await pythonClient.InitializeAsync(languageServerHostService); | ||
return pythonClient; | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
Python/Product/LiveShare/PythonLanguageServiceProviderCallback.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// <copyright> | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Linq; | ||
using Microsoft.Cascade.LanguageServices.Common; | ||
using Microsoft.VisualStudio.LanguageServer.Protocol; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Threading; | ||
using Microsoft.PythonTools.Editor; | ||
using Microsoft.PythonTools.Intellisense; | ||
using LS = Microsoft.PythonTools.Analysis.LanguageServer; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft | ||
{ | ||
internal class PythonLanguageServiceProviderCallback : ILanguageServiceProviderCallback | ||
{ | ||
private SVsServiceProvider serviceProvider; | ||
|
||
public PythonLanguageServiceProviderCallback(SVsServiceProvider serviceProvider) | ||
{ | ||
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
|
||
#pragma warning disable 0067 | ||
public event AsyncEventHandler<LanguageServiceNotifyEventArgs> NotifyAsync; | ||
#pragma warning restore 0067 | ||
|
||
public async Task<TOut> RequestAsync<TIn, TOut>(LspRequest<TIn, TOut> method, TIn param, CancellationToken cancellationToken) | ||
{ | ||
if (method.Name == Methods.Initialize.Name) | ||
{ | ||
var capabilities = new ServerCapabilities { CompletionProvider = new VisualStudio.LanguageServer.Protocol.CompletionOptions { TriggerCharacters = new[] { "." } } }; | ||
object result = new InitializeResult { Capabilities = capabilities }; | ||
return (TOut)(result); | ||
} | ||
if (method.Name == Methods.TextDocumentCompletion.Name) | ||
{ | ||
var completionParams = param as CompletionParams; | ||
var filePath = completionParams.TextDocument.Uri.LocalPath; | ||
VsProjectAnalyzer analyzer = (await serviceProvider.FindAllAnalyzersForFile(filePath)).FirstOrDefault() as VsProjectAnalyzer; | ||
|
||
var lsCompletionParams = JObject.FromObject(completionParams).ToObject<LS.CompletionParams>(); | ||
object list = await analyzer.SendLanguageServerRequestAsync<LS.CompletionParams, LS.CompletionList>(method.Name, lsCompletionParams); | ||
return (TOut)list; | ||
} | ||
|
||
return default(TOut); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011"> | ||
<Metadata> | ||
<Identity Id="2cd11de7-1df1-4d50-8a29-9c0e9a6a548d" Version="15.8.0" Language="en-US" Publisher="Microsoft Corporation" /> | ||
<DisplayName>Python - LiveShare</DisplayName> | ||
<Description xml:space="preserve">Provides LiveShare integration for Python projects</Description> | ||
<MoreInfo>http://aka.ms/ptvs</MoreInfo> | ||
<GettingStartedGuide>http://aka.ms/ptvstutorial</GettingStartedGuide> | ||
</Metadata> | ||
<Installation SystemComponent="true" AllUsers="true" InstalledByMsi="true"> | ||
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0,16.0)" /> | ||
</Installation> | ||
<Dependencies> | ||
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" Version="4.6" /> | ||
<Dependency Id="96492FC7-7BC6-46F7-8559-66BB4E09FD1E" DisplayName="Python" Version="[15.0,16.0)" /> | ||
</Dependencies> | ||
<Prerequisites> | ||
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,16.0)" DisplayName="Visual Studio core editor" /> | ||
</Prerequisites> | ||
<Assets> | ||
<Asset Type="Microsoft.VisualStudio.Assembly" Path="|%CurrentProject%;_GetTargetPath|" AssemblyName="|%CurrentProject%;_GetAssemblyName|" /> | ||
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="|%CurrentProject%;_GetTargetPath|" /> | ||
</Assets> | ||
</PackageManifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters