提交 69fb7891 编写于 作者: D David Barbet

Update license comments, fixup classifications.

上级 8f0938b5
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Composition;
......@@ -32,38 +30,41 @@ public ILanguageService CreateLanguageService(HostLanguageServices languageServi
[ExportLanguageServiceFactory(typeof(ISyntaxClassificationService), StringConstants.CSharpLspLanguageName), Shared]
internal class CSharpLspEditorClassificationFactoryService : ILanguageServiceFactory
{
private readonly RoslynLSPClientServiceFactory roslynLSPClientServiceFactory;
private readonly ClassificationTypeMap classificationTypeMap;
private readonly RoslynLSPClientServiceFactory _roslynLSPClientServiceFactory;
private readonly ClassificationTypeMap _classificationTypeMap;
private readonly ThreadingContext _threadingContext;
[ImportingConstructor]
public CSharpLspEditorClassificationFactoryService(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory, ClassificationTypeMap classificationTypeMap)
public CSharpLspEditorClassificationFactoryService(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory, ClassificationTypeMap classificationTypeMap, IThreadingContext threadingContext)
{
this.roslynLSPClientServiceFactory = roslynLSPClientServiceFactory ?? throw new ArgumentNullException(nameof(roslynLSPClientServiceFactory));
this.classificationTypeMap = classificationTypeMap ?? throw new ArgumentNullException(nameof(classificationTypeMap));
_roslynLSPClientServiceFactory = roslynLSPClientServiceFactory ?? throw new ArgumentNullException(nameof(roslynLSPClientServiceFactory));
_classificationTypeMap = classificationTypeMap ?? throw new ArgumentNullException(nameof(classificationTypeMap));
}
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
{
return new RoslynClassificationService(this.roslynLSPClientServiceFactory, languageServices.GetOriginalLanguageService<ISyntaxClassificationService>(), this.classificationTypeMap);
return new RoslynClassificationService(_roslynLSPClientServiceFactory, languageServices.GetOriginalLanguageService<ISyntaxClassificationService>(), _classificationTypeMap, _threadingContext);
}
}
[ExportLanguageServiceFactory(typeof(ISyntaxClassificationService), StringConstants.VBLspLanguageName), Shared]
internal class VBLspEditorClassificationFactoryService : ILanguageServiceFactory
{
private readonly RoslynLSPClientServiceFactory roslynLSPClientServiceFactory;
private readonly ClassificationTypeMap classificationTypeMap;
private readonly RoslynLSPClientServiceFactory _roslynLSPClientServiceFactory;
private readonly ClassificationTypeMap _classificationTypeMap;
private readonly IThreadingContext _threadingContext;
[ImportingConstructor]
public VBLspEditorClassificationFactoryService(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory, ClassificationTypeMap classificationTypeMap)
public VBLspEditorClassificationFactoryService(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory, ClassificationTypeMap classificationTypeMap, IThreadingContext threadingContext)
{
this.roslynLSPClientServiceFactory = roslynLSPClientServiceFactory ?? throw new ArgumentNullException(nameof(roslynLSPClientServiceFactory));
this.classificationTypeMap = classificationTypeMap ?? throw new ArgumentNullException(nameof(classificationTypeMap));
_roslynLSPClientServiceFactory = roslynLSPClientServiceFactory ?? throw new ArgumentNullException(nameof(roslynLSPClientServiceFactory));
_classificationTypeMap = classificationTypeMap ?? throw new ArgumentNullException(nameof(classificationTypeMap));
_threadingContext = threadingContext;
}
public ILanguageService CreateLanguageService(HostLanguageServices languageServices)
{
return new RoslynClassificationService(this.roslynLSPClientServiceFactory, languageServices.GetOriginalLanguageService<ISyntaxClassificationService>(), this.classificationTypeMap);
return new RoslynClassificationService(_roslynLSPClientServiceFactory, languageServices.GetOriginalLanguageService<ISyntaxClassificationService>(), _classificationTypeMap, _threadingContext);
}
}
}
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
......@@ -9,36 +7,40 @@
using Microsoft.CodeAnalysis.Classification;
using Microsoft.CodeAnalysis.Classification.Classifiers;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.LanguageServer.CustomProtocol;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServer.Protocol;
using Microsoft.VisualStudio.LanguageServices.Remote.Shared.CustomProtocol;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.LanguageServices.LiveShare.CustomProtocol;
using Task = System.Threading.Tasks.Task;
namespace Microsoft.VisualStudio.LanguageServices.LiveShare.Client
{
internal class RoslynClassificationService : ISyntaxClassificationService
{
private readonly RoslynLSPClientServiceFactory roslynLSPClientServiceFactory;
private readonly ISyntaxClassificationService originalService;
private readonly ClassificationTypeMap classificationTypeMap;
private readonly RoslynLSPClientServiceFactory _roslynLSPClientServiceFactory;
private readonly ISyntaxClassificationService _originalService;
private readonly ClassificationTypeMap _classificationTypeMap;
private readonly IThreadingContext _threadingContext;
public RoslynClassificationService(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory, ISyntaxClassificationService originalService, ClassificationTypeMap classificationTypeMap)
public RoslynClassificationService(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory, ISyntaxClassificationService originalService,
ClassificationTypeMap classificationTypeMap, IThreadingContext threadingContext)
{
this.roslynLSPClientServiceFactory = roslynLSPClientServiceFactory ?? throw new ArgumentNullException(nameof(roslynLSPClientServiceFactory));
this.originalService = originalService ?? throw new ArgumentNullException(nameof(originalService));
this.classificationTypeMap = classificationTypeMap ?? throw new ArgumentNullException(nameof(classificationTypeMap));
_roslynLSPClientServiceFactory = roslynLSPClientServiceFactory ?? throw new ArgumentNullException(nameof(roslynLSPClientServiceFactory));
_originalService = originalService ?? throw new ArgumentNullException(nameof(originalService));
_classificationTypeMap = classificationTypeMap ?? throw new ArgumentNullException(nameof(classificationTypeMap));
_threadingContext = threadingContext;
}
public void AddLexicalClassifications(SourceText text, TextSpan textSpan, ArrayBuilder<ClassifiedSpan> result, CancellationToken cancellationToken)
{
this.originalService.AddLexicalClassifications(text, textSpan, result, cancellationToken);
_originalService.AddLexicalClassifications(text, textSpan, result, cancellationToken);
}
public void AddSemanticClassifications(SemanticModel semanticModel, TextSpan textSpan, Workspace workspace, Func<SyntaxNode, ImmutableArray<ISyntaxClassifier>> getNodeClassifiers, Func<SyntaxToken, ImmutableArray<ISyntaxClassifier>> getTokenClassifiers, ArrayBuilder<ClassifiedSpan> result, CancellationToken cancellationToken)
{
ThreadHelper.JoinableTaskFactory.Run(async () =>
_threadingContext.JoinableTaskFactory.Run(async () =>
{
var sourceText = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
await AddRemoteSemanticClassificationsAsync(sourceText, semanticModel.SyntaxTree.FilePath, textSpan, result, cancellationToken).ConfigureAwait(false);
......@@ -60,7 +62,7 @@ public async Task AddSemanticClassificationsAsync(Document document, TextSpan te
private async Task AddRemoteSemanticClassificationsAsync(SourceText text, string filePath, TextSpan textSpan, ArrayBuilder<ClassifiedSpan> result, CancellationToken cancellationToken)
{
var lspClient = this.roslynLSPClientServiceFactory.ActiveLanguageServerClient;
var lspClient = _roslynLSPClientServiceFactory.ActiveLanguageServerClient;
if (lspClient == null)
{
return;
......@@ -69,10 +71,11 @@ private async Task AddRemoteSemanticClassificationsAsync(SourceText text, string
var classificationParams = new ClassificationParams
{
TextDocument = new TextDocumentIdentifier { Uri = lspClient.ProtocolConverter.ToProtocolUri(new Uri(filePath)) },
Range = textSpan.ToRange(text)
Range = ProtocolConversions.TextSpanToRange(textSpan, text)
};
ClassificationSpan[] classificationSpans = await lspClient.RequestAsync(RoslynMethods.Classifications, classificationParams, cancellationToken).ConfigureAwait(false);
var request = new LspRequest<ClassificationParams, ClassificationSpan[]>(RoslynMethods.ClassificationsName);
var classificationSpans = await lspClient.RequestAsync(request, classificationParams, cancellationToken).ConfigureAwait(false);
if (classificationSpans == null)
{
return;
......@@ -83,12 +86,12 @@ private async Task AddRemoteSemanticClassificationsAsync(SourceText text, string
// The host may return more classifications than are supported by the guest. As an example, 15.7 added classifications for type members which wouldnt be understood by a 15.6 guest.
// Check with the classificationTypeMap to see if this is a known classification.
var classification = classificationSpan.Classification;
if (this.classificationTypeMap.GetClassificationType(classification) == null)
if (_classificationTypeMap.GetClassificationType(classification) == null)
{
classification = ClassificationTypeNames.Identifier;
}
var span = classificationSpan.Range.ToTextSpan(text);
var span = ProtocolConversions.RangeToTextSpan(classificationSpan.Range, text);
if (span.End <= text.Length)
{
result.Add(new ClassifiedSpan(classification, span));
......@@ -98,17 +101,17 @@ private async Task AddRemoteSemanticClassificationsAsync(SourceText text, string
public void AddSyntacticClassifications(SyntaxTree syntaxTree, TextSpan textSpan, ArrayBuilder<ClassifiedSpan> result, CancellationToken cancellationToken)
{
this.originalService.AddSyntacticClassifications(syntaxTree, textSpan, result, cancellationToken);
_originalService.AddSyntacticClassifications(syntaxTree, textSpan, result, cancellationToken);
}
public ClassifiedSpan FixClassification(SourceText text, ClassifiedSpan classifiedSpan)
{
return this.originalService.FixClassification(text, classifiedSpan);
return _originalService.FixClassification(text, classifiedSpan);
}
public ImmutableArray<ISyntaxClassifier> GetDefaultSyntaxClassifiers()
{
return this.originalService.GetDefaultSyntaxClassifiers();
return _originalService.GetDefaultSyntaxClassifiers();
}
}
}
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.Cascade.Common;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.Cascade.Common;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
......
using System;
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Composition;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Completion;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Threading;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.Cascade.Common;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.VisualStudio.LanguageServices.LiveShare.Client
{
internal static class HostLanguageServicesExtensions
{
public static TLanguageService GetOriginalLanguageService<TLanguageService>(this HostLanguageServices languageServices) where TLanguageService : class, ILanguageService
{
var language = languageServices.Language;
var originalLanguage = language;
switch (language)
{
case StringConstants.CSharpLspLanguageName:
originalLanguage = LanguageNames.CSharp;
break;
case StringConstants.VBLspLanguageName:
originalLanguage = LanguageNames.VisualBasic;
break;
default:
// Unknown language.
return null;
}
return languageServices.WorkspaceServices.GetLanguageServices(originalLanguage).GetService<TLanguageService>();
}
}
}
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.Cascade.Common;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.CodeAnalysis;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Threading;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading;
using System.Threading.Tasks;
......
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Composition;
using Microsoft.Cascade.Common;
using Microsoft.CodeAnalysis.SignatureHelp;
namespace Microsoft.VisualStudio.LanguageServices.LiveShare.Client
{
[Shared]
[ExportSignatureHelpProvider("CSharpLspSignatureHelpProvider", StringConstants.CSharpLspLanguageName)]
internal class CSharpLspSignatureHelpProvider : RoslynSignatureHelpProvider
{
[ImportingConstructor]
public CSharpLspSignatureHelpProvider(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory, IVsConfigurationSettings configurationSettings)
: base(roslynLSPClientServiceFactory, configurationSettings )
public CSharpLspSignatureHelpProvider(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory)
: base(roslynLSPClientServiceFactory)
{
}
}
[Shared]
[ExportSignatureHelpProvider("VBLspSignatureHelpProvider", StringConstants.VBLspLanguageName)]
internal class VBLspSignatureHelpProvider : RoslynSignatureHelpProvider
{
[ImportingConstructor]
public VBLspSignatureHelpProvider(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory, IVsConfigurationSettings configurationSettings)
: base(roslynLSPClientServiceFactory, configurationSettings)
public VBLspSignatureHelpProvider(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory)
: base(roslynLSPClientServiceFactory)
{
}
}
#if !VS_16_0
[ExportSignatureHelpProvider("TypeScriptLspSignatureHelpProvider", StringConstants.TypeScriptLanguageName)]
internal class TypeScriptLspSignatureHelpProvider : RoslynSignatureHelpProvider
{
[ImportingConstructor]
public TypeScriptLspSignatureHelpProvider(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory, IVsConfigurationSettings configurationSettings)
: base(roslynLSPClientServiceFactory, configurationSettings)
{
}
}
#endif
}
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......@@ -8,7 +6,6 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Cascade.Common;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.SignatureHelp;
using Microsoft.VisualStudio.LanguageServer.Protocol;
......@@ -18,13 +15,10 @@ namespace Microsoft.VisualStudio.LanguageServices.LiveShare.Client
class RoslynSignatureHelpProvider : ISignatureHelpProvider
{
private readonly RoslynLSPClientServiceFactory roslynLSPClientServiceFactory;
private readonly IVsConfigurationSettings configurationSettings;
public RoslynSignatureHelpProvider(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory,
IVsConfigurationSettings configurationSettings)
public RoslynSignatureHelpProvider(RoslynLSPClientServiceFactory roslynLSPClientServiceFactory)
{
this.roslynLSPClientServiceFactory = roslynLSPClientServiceFactory ?? throw new ArgumentNullException(nameof(roslynLSPClientServiceFactory));
this.configurationSettings = configurationSettings ?? throw new ArgumentNullException(nameof(configurationSettings));
}
public bool IsTriggerCharacter(char ch)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册