public OnAutoInsertEndpoint( ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher, DocumentResolver documentResolver, IEnumerable <RazorOnAutoInsertProvider> onAutoInsertProvider, AdhocWorkspaceFactory workspaceFactory) { if (projectSnapshotManagerDispatcher is null) { throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher)); } if (documentResolver is null) { throw new ArgumentNullException(nameof(documentResolver)); } if (onAutoInsertProvider is null) { throw new ArgumentNullException(nameof(onAutoInsertProvider)); } if (workspaceFactory is null) { throw new ArgumentNullException(nameof(workspaceFactory)); } _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher; _documentResolver = documentResolver; _workspaceFactory = workspaceFactory; _onAutoInsertProviders = onAutoInsertProvider.ToList(); _onAutoInsertTriggerCharacters = _onAutoInsertProviders.Select(provider => provider.TriggerCharacter).ToList(); }
public static FormattingContext Create( DocumentUri uri, DocumentSnapshot originalSnapshot, RazorCodeDocument codeDocument, FormattingOptions options, AdhocWorkspaceFactory workspaceFactory) { return(CreateCore(uri, originalSnapshot, codeDocument, options, workspaceFactory, isFormatOnType: false, automaticallyAddUsings: false, hostDocumentIndex: 0, triggerCharacter: '\0')); }
private static FormattingContext CreateCore( DocumentUri uri, DocumentSnapshot originalSnapshot, RazorCodeDocument codeDocument, FormattingOptions options, AdhocWorkspaceFactory workspaceFactory, bool isFormatOnType, bool automaticallyAddUsings, int hostDocumentIndex, char triggerCharacter) { if (uri is null) { throw new ArgumentNullException(nameof(uri)); } if (originalSnapshot is null) { throw new ArgumentNullException(nameof(originalSnapshot)); } if (codeDocument is null) { throw new ArgumentNullException(nameof(codeDocument)); } if (options is null) { throw new ArgumentNullException(nameof(options)); } if (workspaceFactory is null) { throw new ArgumentNullException(nameof(workspaceFactory)); } // hostDocumentIndex, triggerCharacter and automaticallyAddUsings are only supported in on type formatting Debug.Assert(isFormatOnType || (hostDocumentIndex == 0 && triggerCharacter == '\0' && automaticallyAddUsings == false)); var result = new FormattingContext( workspaceFactory, uri, originalSnapshot, codeDocument, options, isFormatOnType, automaticallyAddUsings, hostDocumentIndex, triggerCharacter ); return(result); }
public static FormattingContext CreateForOnTypeFormatting( DocumentUri uri, DocumentSnapshot originalSnapshot, RazorCodeDocument codeDocument, FormattingOptions options, AdhocWorkspaceFactory workspaceFactory, bool automaticallyAddUsings, int hostDocumentIndex, char triggerCharacter) { return(CreateCore(uri, originalSnapshot, codeDocument, options, workspaceFactory, isFormatOnType: true, automaticallyAddUsings, hostDocumentIndex, triggerCharacter)); }
private FormattingContext(AdhocWorkspaceFactory workspaceFactory, DocumentUri uri, DocumentSnapshot originalSnapshot, RazorCodeDocument codeDocument, FormattingOptions options, bool isFormatOnType, bool automaticallyAddUsings, int hostDocumentIndex, char triggerCharacter) { _workspaceFactory = workspaceFactory; Uri = uri; OriginalSnapshot = originalSnapshot; CodeDocument = codeDocument; Options = options; IsFormatOnType = isFormatOnType; AutomaticallyAddUsings = automaticallyAddUsings; HostDocumentIndex = hostDocumentIndex; TriggerCharacter = triggerCharacter; }
public RazorFormattingEndpoint( ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher, DocumentResolver documentResolver, RazorFormattingService razorFormattingService, RazorDocumentMappingService razorDocumentMappingService, AdhocWorkspaceFactory adhocWorkspaceFactory, IOptionsMonitor <RazorLSPOptions> optionsMonitor, ILoggerFactory loggerFactory) { if (projectSnapshotManagerDispatcher is null) { throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher)); } if (documentResolver is null) { throw new ArgumentNullException(nameof(documentResolver)); } if (razorFormattingService is null) { throw new ArgumentNullException(nameof(razorFormattingService)); } if (razorDocumentMappingService is null) { throw new ArgumentNullException(nameof(razorDocumentMappingService)); } if (adhocWorkspaceFactory is null) { throw new ArgumentNullException(nameof(adhocWorkspaceFactory)); } if (optionsMonitor is null) { throw new ArgumentNullException(nameof(optionsMonitor)); } if (loggerFactory is null) { throw new ArgumentNullException(nameof(loggerFactory)); } _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher; _documentResolver = documentResolver; _razorFormattingService = razorFormattingService; _razorDocumentMappingService = razorDocumentMappingService; _adhocWorkspaceFactory = adhocWorkspaceFactory; _optionsMonitor = optionsMonitor; _logger = loggerFactory.CreateLogger <RazorFormattingEndpoint>(); }
public InlineCompletionEndpoint( ProjectSnapshotManagerDispatcher projectSnapshotManagerDispatcher, DocumentResolver documentResolver, RazorDocumentMappingService documentMappingService, ClientNotifierServiceBase languageServer, AdhocWorkspaceFactory adhocWorkspaceFactory, ILoggerFactory loggerFactory) { if (projectSnapshotManagerDispatcher is null) { throw new ArgumentNullException(nameof(projectSnapshotManagerDispatcher)); } if (documentResolver is null) { throw new ArgumentNullException(nameof(documentResolver)); } if (documentMappingService is null) { throw new ArgumentNullException(nameof(documentMappingService)); } if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } if (adhocWorkspaceFactory is null) { throw new ArgumentNullException(nameof(adhocWorkspaceFactory)); } if (loggerFactory is null) { throw new ArgumentNullException(nameof(loggerFactory)); } _projectSnapshotManagerDispatcher = projectSnapshotManagerDispatcher; _documentResolver = documentResolver; _documentMappingService = documentMappingService; _languageServer = languageServer; _adhocWorkspaceFactory = adhocWorkspaceFactory; _logger = loggerFactory.CreateLogger <InlineCompletionEndpoint>(); }
public DefaultRazorFormattingService( IEnumerable <IFormattingPass> formattingPasses, ILoggerFactory loggerFactory, AdhocWorkspaceFactory workspaceFactory) { if (formattingPasses is null) { throw new ArgumentNullException(nameof(formattingPasses)); } if (loggerFactory is null) { throw new ArgumentNullException(nameof(loggerFactory)); } if (workspaceFactory is null) { throw new ArgumentNullException(nameof(workspaceFactory)); } _formattingPasses = formattingPasses.OrderBy(f => f.Order).ToList(); _logger = loggerFactory.CreateLogger <DefaultRazorFormattingService>(); _workspaceFactory = workspaceFactory; }
private FormattingContext(AdhocWorkspaceFactory workspaceFactory) { _workspaceFactory = workspaceFactory; }
public static FormattingContext Create( DocumentUri uri, DocumentSnapshot originalSnapshot, RazorCodeDocument codeDocument, FormattingOptions options, AdhocWorkspaceFactory workspaceFactory, bool isFormatOnType = false) { if (uri is null) { throw new ArgumentNullException(nameof(uri)); } if (originalSnapshot is null) { throw new ArgumentNullException(nameof(originalSnapshot)); } if (codeDocument is null) { throw new ArgumentNullException(nameof(codeDocument)); } if (options is null) { throw new ArgumentNullException(nameof(options)); } if (workspaceFactory is null) { throw new ArgumentNullException(nameof(workspaceFactory)); } var syntaxTree = codeDocument.GetSyntaxTree(); var formattingSpans = syntaxTree.GetFormattingSpans(); var result = new FormattingContext(workspaceFactory) { Uri = uri, OriginalSnapshot = originalSnapshot, CodeDocument = codeDocument, Options = options, IsFormatOnType = isFormatOnType, FormattingSpans = formattingSpans }; var sourceText = codeDocument.GetSourceText(); var indentations = new Dictionary <int, IndentationContext>(); var previousIndentationLevel = 0; for (var i = 0; i < sourceText.Lines.Count; i++) { // Get first non-whitespace character position var nonWsPos = sourceText.Lines[i].GetFirstNonWhitespacePosition(); var existingIndentation = (nonWsPos ?? sourceText.Lines[i].End) - sourceText.Lines[i].Start; // The existingIndentation above is measured in characters, and is used to create text edits // The below is measured in columns, so takes into account tab size. This is useful for creating // new indentation strings var existingIndentationSize = sourceText.Lines[i].GetIndentationSize(options.TabSize); var emptyOrWhitespaceLine = false; if (nonWsPos == null) { emptyOrWhitespaceLine = true; nonWsPos = sourceText.Lines[i].Start; } // position now contains the first non-whitespace character or 0. Get the corresponding FormattingSpan. if (result.TryGetFormattingSpan(nonWsPos.Value, out var span)) { indentations[i] = new IndentationContext(firstSpan: span) { Line = i, RazorIndentationLevel = span.RazorIndentationLevel, HtmlIndentationLevel = span.HtmlIndentationLevel, RelativeIndentationLevel = span.IndentationLevel - previousIndentationLevel, ExistingIndentation = existingIndentation, ExistingIndentationSize = existingIndentationSize, EmptyOrWhitespaceLine = emptyOrWhitespaceLine, }; previousIndentationLevel = span.IndentationLevel; } else { // Couldn't find a corresponding FormattingSpan. Happens if it is a 0 length line. // Let's create a 0 length span to represent this and default it to HTML. var placeholderSpan = new FormattingSpan( new Language.Syntax.TextSpan(nonWsPos.Value, 0), new Language.Syntax.TextSpan(nonWsPos.Value, 0), FormattingSpanKind.Markup, FormattingBlockKind.Markup, razorIndentationLevel: 0, htmlIndentationLevel: 0, isInClassBody: false, componentLambdaNestingLevel: 0); indentations[i] = new IndentationContext(firstSpan: placeholderSpan) { Line = i, RazorIndentationLevel = 0, HtmlIndentationLevel = 0, RelativeIndentationLevel = previousIndentationLevel, ExistingIndentation = existingIndentation, ExistingIndentationSize = existingIndentation, EmptyOrWhitespaceLine = emptyOrWhitespaceLine, }; } } result.Indentations = indentations; return(result); }
private FormattingContext(RazorProjectEngine engine, IReadOnlyList <RazorSourceDocument> importSources, AdhocWorkspaceFactory workspaceFactory, DocumentUri uri, DocumentSnapshot originalSnapshot, RazorCodeDocument codeDocument, FormattingOptions options, bool isFormatOnType, bool automaticallyAddUsings, int hostDocumentIndex, char triggerCharacter) : this(workspaceFactory, uri, originalSnapshot, codeDocument, options, isFormatOnType, automaticallyAddUsings, hostDocumentIndex, triggerCharacter) { _engine = engine; _importSources = importSources; }