Skip to content

Commit

Permalink
Merge pull request microsoft#4882 from zooba/liveshare
Browse files Browse the repository at this point in the history
Fixes microsoft#4734 Live Share support
  • Loading branch information
zooba authored Nov 30, 2018
2 parents abbbe57 + 6c138dd commit 4ccbb06
Show file tree
Hide file tree
Showing 39 changed files with 828 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ BuildOutput/
packages/
packages.14.0/
packages.15.0/
packages.16.0/
*.sdf
*.opensdf
*.suo
Expand Down
4 changes: 4 additions & 0 deletions Build/15.0/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<package id="Microsoft.VSSDK.BuildTools" version="15.8.3252" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="MicroBuild.Core" version="0.2.0" />
<package id="Microsoft.VisualStudio.LiveShare" version="0.3.959" />
<package id="Microsoft.VisualStudio.LiveShare.LanguageServices" version="0.3.959" />
<package id="Microsoft.VisualStudio.Debugger.InteropA" version="9.0.21022" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Debugger.Interop.10.0" version="10.0.30320" />
<package id="Microsoft.VisualStudio.Debugger.Interop.11.0" version="11.0.50728" />
Expand Down Expand Up @@ -53,6 +55,8 @@
<package id="Microsoft.VisualStudio.Language.Intellisense" version="15.8.525" />
<package id="Microsoft.VisualStudio.Language.StandardClassification" version="15.8.525" />
<package id="Microsoft.VisualStudio.Language.NavigateTo.Interfaces" version="15.8.525" />
<package id="Microsoft.VisualStudio.LanguageServer.Client" version="15.9.1" />
<package id="Microsoft.VisualStudio.LanguageServer.Protocol" version="15.9.1" />
<package id="Microsoft.VisualStudio.Shared.VSCodeDebugProtocol" version="15.8.20719.1"/>
<package id="Microsoft.VisualStudio.Text.Data" version="15.8.525" />
<package id="Microsoft.VisualStudio.Text.Logic" version="15.8.525" />
Expand Down
5 changes: 5 additions & 0 deletions Build/16.0/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<package id="Microsoft.VSSDK.BuildTools" version="15.8.3252" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="MicroBuild.Core" version="0.2.0" />
<package id="Microsoft.VisualStudio.LiveShare" version="0.3.959" />
<package id="Microsoft.VisualStudio.LiveShare.LanguageServices" version="0.3.959" />
<package id="Microsoft.VisualStudio.Cascade.Contracts" version="0.3.536" />
<package id="Microsoft.VisualStudio.Debugger.InteropA" version="9.0.21022" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Debugger.Interop.10.0" version="10.0.30320" />
<package id="Microsoft.VisualStudio.Debugger.Interop.11.0" version="11.0.50728" />
Expand Down Expand Up @@ -42,6 +45,8 @@
<package id="Microsoft.DotNet.PlatformAbstractions" version="2.1.0" />

<package id="Microsoft.VisualStudio.Debugger.DebugAdapterHost.Interfaces" version="15.8.20619.1"/>
<package id="Microsoft.VisualStudio.LanguageServer.Client" version="15.9.1" />
<package id="Microsoft.VisualStudio.LanguageServer.Protocol" version="15.9.1" />
<package id="Microsoft.VisualStudio.Shared.VSCodeDebugProtocol" version="15.8.20719.1"/>
<package id="Microsoft.VisualStudio.Validation" version="15.3.58" />

Expand Down
1 change: 1 addition & 0 deletions Build/Common.Build.CSharp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<_NugetAssemblies Include="$(PackagesPath)\Microsoft.VisualStudio.*\lib\net35\Microsoft.VisualStudio.*.dll" />
<_NugetAssemblies Include="$(PackagesPath)\Microsoft.VisualStudio.*\lib\net45\Microsoft.VisualStudio.*.dll" />
<_NugetAssemblies Include="$(PackagesPath)\Microsoft.VisualStudio.*\lib\net46\Microsoft.VisualStudio.*.dll" />
<_NugetAssemblies Include="$(PackagesPath)\Microsoft.VisualStudio.*\lib\net461\Microsoft.VisualStudio.*.dll" />
</ItemGroup>
<PropertyGroup>
<AssemblySearchPaths>
Expand Down
Binary file modified Build/NuGet.exe
Binary file not shown.
6 changes: 5 additions & 1 deletion Build/PreBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ $outdir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPat
pushd "$buildroot\Build"
try {
$arglist = "restore", "$vstarget\packages.config", "-OutputDirectory", $outdir, "-Config", "$vstarget\nuget.config", "-NonInteractive"
Start-Process -Wait -NoNewWindow .\nuget.exe -ErrorAction Stop -ArgumentList $arglist
$nuget = gcm nuget.exe -EA 0
if (-not $nuget) {
$nuget = gcm .\nuget.exe
}
Start-Process -Wait -NoNewWindow $nuget.Source -ErrorAction Stop -ArgumentList $arglist

$versions = @{}
([xml](gc "$vstarget\packages.config")).packages.package | %{ $versions[$_.id] = $_.version }
Expand Down
6 changes: 3 additions & 3 deletions Python/Product/Analysis/LanguageServer/CompletionAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,11 @@ private CompletionItem ToCompletionItem(MemberResult m) {
label = m.Name,
insertText = completion,
documentation = string.IsNullOrWhiteSpace(doc) ? null : new MarkupContent {
kind = _textBuilder.DisplayOptions.preferredFormat,
kind = _textBuilder.DisplayOptions.preferredFormat ?? MarkupKind.PlainText,
value = doc
},
// Place regular items first, advanced entries last
sortText = char.IsLetter(completion, 0) ? "1" : "2",
sortText = (char.IsLetter(completion, 0) ? "1" : "2") + m.Name,
kind = ToCompletionItemKind(m.MemberType),
_kind = m.MemberType.ToString().ToLowerInvariant()
};
Expand All @@ -836,7 +836,7 @@ private static CompletionItem ToCompletionItem(string text, PythonMemberType typ
label = label ?? text,
insertText = text,
// Place regular items first, advanced entries last
sortText = char.IsLetter(text, 0) ? "1" : "2",
sortText = (char.IsLetter(text, 0) ? "1" : "2") + (label ?? text),
kind = ToCompletionItemKind(type),
_kind = type.ToString().ToLowerInvariant()
};
Expand Down
11 changes: 10 additions & 1 deletion Python/Product/Analyzer/Intellisense/OutOfProcProjectAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,18 @@ private async Task RequestHandler(RequestArgs requestArgs, Func<Response, Task>
private async Task<Response> ProcessLanguageServerRequest(AP.LanguageServerRequest request) {
try {
var body = (Newtonsoft.Json.Linq.JObject)request.body;
object result = null;

switch (request.name) {
case "textDocument/completion": return new AP.LanguageServerResponse { body = await _server.Completion(body.ToObject<LS.CompletionParams>()) };
case "textDocument/completion": result = await _server.Completion(body.ToObject<LS.CompletionParams>()); break;
case "textDocument/hover": result = await _server.Hover(body.ToObject<LS.TextDocumentPositionParams>()); break;
case "textDocument/definition": result = await _server.GotoDefinition(body.ToObject<LS.TextDocumentPositionParams>()); break;
case "textDocument/references": result = await _server.FindReferences(body.ToObject<LS.ReferencesParams>()); break;
case "textDocument/signatureHelp": result = await _server.SignatureHelp(body.ToObject<LS.TextDocumentPositionParams>()); break;
}

if (result != null) {
return new AP.LanguageServerResponse { body = result };
}

return new AP.LanguageServerResponse { error = "Unknown command: " + request.name };
Expand Down
2 changes: 1 addition & 1 deletion Python/Product/Ipc.Json/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ await SendMessage(
/// Base protocol defined at https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#base-protocol
/// </remarks>
private async Task SendMessage(ProtocolMessage packet, CancellationToken cancel) {
var str = JsonConvert.SerializeObject(packet);
var str = JsonConvert.SerializeObject(packet, UriJsonConverter.Instance);

try {
try {
Expand Down
2 changes: 2 additions & 0 deletions Python/Product/Ipc.Json/UriJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

namespace Microsoft.PythonTools.Ipc.Json {
public sealed class UriJsonConverter : JsonConverter {
public static readonly JsonConverter Instance = new UriJsonConverter();

public override bool CanConvert(Type objectType) {
return typeof(Uri).IsAssignableFrom(objectType);
}
Expand Down
99 changes: 99 additions & 0 deletions Python/Product/LiveShare/LiveShare.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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>
<ProjectReference Include="..\VSCommon\VSCommon.csproj">
<Project>{a52ac77f-6df9-4387-bb08-8ded3fd95a0f}</Project>
<Name>VSCommon</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.LiveShare" />
<Reference Include="Microsoft.VisualStudio.LiveShare.LanguageServices" />
<Reference Include="Microsoft.VisualStudio.Text.Data" />
<Reference Include="Microsoft.VisualStudio.Threading" />
<Reference Include="Microsoft.VisualStudio.Shell.Framework" />
<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="Properties\AssemblyInfo.cs" />
<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>
-->
</Project>
29 changes: 29 additions & 0 deletions Python/Product/LiveShare/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Python Tools for Visual Studio
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the License); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("Visual Studio - Python Live Share support")]
[assembly: AssemblyDescription("Provides integration for Live Share.")]
[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
[assembly: NeutralResourcesLanguage("en-US")]

[assembly: InternalsVisibleTo("PythonToolsTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
60 changes: 60 additions & 0 deletions Python/Product/LiveShare/PythonLanguageClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Python Tools for Visual Studio
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the License); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System;
using Microsoft.VisualStudio.LiveShare;
using Microsoft.VisualStudio.LiveShare.LanguageServices;
using Microsoft.VisualStudio.Threading;
using Task = System.Threading.Tasks.Task;

namespace Microsoft.PythonTools.LiveShare {
internal class PythonLanguageClient : ICollaborationService, IAsyncDisposable {
private static string[] PythonContentTypes = new string[] { PythonCoreConstants.ContentType };
private static DocumentFilter[] PythonDocumentFilters = new[] {
new DocumentFilter() { Language = "python" }
};

private IAsyncDisposable _languageServiceProviderService;
private readonly IServiceProvider _serviceProvider;

public PythonLanguageClient(IServiceProvider serviceProvider) {
_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(_serviceProvider);
_languageServiceProviderService = await languageServerHostService.CreateCustomLanguageServerProviderAsync(
"languageServerProvider-python",
new LanguageServerProviderMetadata {
IsLanguageClientProvider = false,
ContentTypes = PythonContentTypes,
DocumentFilters = PythonDocumentFilters
},
pythonLanguageServiceProviderCallback,
null);
}

public async Task DisposeAsync() {
if (_languageServiceProviderService != null) {
await _languageServiceProviderService.DisposeAsync();
}
}
}
}
46 changes: 46 additions & 0 deletions Python/Product/LiveShare/PythonLanguageClientFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Python Tools for Visual Studio
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the License); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System;
using System.ComponentModel.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.LiveShare;
using Microsoft.VisualStudio.LiveShare.LanguageServices;
using Microsoft.VisualStudio.Shell;

namespace Microsoft.PythonTools.LiveShare {
[ExportCollaborationService(typeof(PythonLanguageClient), Scope = SessionScope.Host)]
internal class PythonLanguageClientFactory : ICollaborationServiceFactory {
private readonly IServiceProvider _serviceProvider;

[ImportingConstructor]
public PythonLanguageClientFactory([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider) {
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
}

public async Task<ICollaborationService> CreateServiceAsync(CollaborationSession session, CancellationToken cancellationToken) {
var languageServerHostService = session.GetService(typeof(ILanguageServerHostService)) as ILanguageServerHostService;
if (languageServerHostService == null) {
return null;
}

var pythonClient = new PythonLanguageClient(_serviceProvider);
await pythonClient.InitializeAsync(languageServerHostService);
return pythonClient;
}
}
}
Loading

0 comments on commit 4ccbb06

Please sign in to comment.