Beispiel #1
0
        private void HandleDidChangeNotification(string paramsJson)
        {
            Contracts.AssertValue(paramsJson);

            if (!TryParseParams(paramsJson, out DidChangeTextDocumentParams didChangeParams))
            {
                _sendToClient(JsonRpcHelper.CreateErrorResult(null, JsonRpcHelper.ErrorCode.ParseError));
                return;
            }

            if (didChangeParams.ContentChanges.Length != 1)
            {
                _sendToClient(JsonRpcHelper.CreateErrorResult(null, JsonRpcHelper.ErrorCode.InvalidParams));
                return;
            }

            OnDidChange?.Invoke(didChangeParams);

            var documentUri = didChangeParams.TextDocument.Uri;
            var scope       = _scopeFactory.GetOrCreateInstance(documentUri);

            var expression = didChangeParams.ContentChanges[0].Text;
            var result     = scope.Check(expression);

            PublishDiagnosticsNotification(documentUri, expression, result.Errors);

            PublishTokens(documentUri, result);
        }
        private bool EmitChangeEvent(Range currentRange, bool textChanged, bool propertiesChanged)
        {
            MarkerSnapshot oldState = PreviousEventState;

            currentRange = currentRange ?? GetRange();

            if (!propertiesChanged &&
                oldState.Valid == Valid &&
                oldState.Tailed == Tailed &&
                oldState.Reversed == Reversed &&
                oldState.Range.CompareTo(currentRange) == 0)
            {
                return(false);
            }

            MarkerSnapshot newState = PreviousEventState = GetSnapshot(currentRange);

            Point oldHeadPosition, oldTailPosition, newHeadPosition, newTailPosition;

            if (oldState.Reversed)
            {
                oldHeadPosition = oldState.Range.Start;
                oldTailPosition = oldState.Range.End;
            }
            else
            {
                oldHeadPosition = oldState.Range.End;
                oldTailPosition = oldState.Range.Start;
            }

            if (newState.Reversed)
            {
                newHeadPosition = newState.Range.Start;
                newTailPosition = newState.Range.End;
            }
            else
            {
                newHeadPosition = newState.Range.End;
                newTailPosition = newState.Range.Start;
            }

            OnDidChange.Invoke(
                new OnDidChangeEventArgs(
                    oldState.Valid, newState.Valid, oldState.Tailed, newState.Tailed,
                    oldState.Properties, newState.Properties,
                    oldHeadPosition, newHeadPosition,
                    oldTailPosition, newTailPosition,
                    textChanged));
            return(true);
        }