public void Start()
        {
            Task.Run(() =>
            {
                var watch = System.Diagnostics.Stopwatch.StartNew();
                BuildIndex();
                watch.Stop();

                DoneIndexing = true;

                var results = new CommandResult
                {
                    IsInternal  = true,
                    MessageType = IPCMessage.LanguageServerIndexingComplete,
                    Message     = ServerConstants.LANGUAGE_SERVER_INDEXING_COMPLETE,
                    Metadata    = $"{watch.ElapsedMilliseconds / 1000}"
                };

                Console.WriteLine(_serializer.Serialize(results));
                Console.Out.Flush();

                Clean();
            });
        }
Beispiel #2
0
        public string Provide(string incomingPayload)
        {
            var request = _serializer.Deserialize <Request>(incomingPayload);

            if (!WorkspaceSymbolParser.DoneIndexing)
            {
                return(HandlePreIndexRequest(request));
            }

            // We are not handling anything in a try/catch
            // because we want the program to crash
            // it will be handled by the parent process
            var results = "";

            switch (request.Lookup)
            {
            case CommandType.Definitions:
                var definitionResults = ProvideDefinition(request);
                if (definitionResults != null)
                {
                    results = _serializer.Serialize(definitionResults);
                }
                else
                {
                    var notFound = new CommandResult
                    {
                        IsInternal  = true,
                        RequestId   = request.Id,
                        MessageType = IPCMessage.SymbolNotFound,
                        Message     = ServerConstants.SYMBOL_NOT_FOUND
                    };
                    results = _serializer.Serialize(notFound);
                }
                break;

            case CommandType.Symbols:
                var symbolResults = ProvideSymbols(request);
                if (symbolResults != null)
                {
                    results = _serializer.Serialize(symbolResults);
                }
                break;

            case CommandType.Diagnostics:
                var diagResults = ProvideDiagnostics(request);
                if (diagResults != null)
                {
                    results = _serializer.Serialize(diagResults);
                }
                break;

            case CommandType.Hover:
                var hoverResults = ProvideHover(request);
                if (hoverResults != null)
                {
                    results = _serializer.Serialize(hoverResults);
                }
                else
                {
                    var notFound = new CommandResult
                    {
                        IsInternal  = true,
                        RequestId   = request.Id,
                        MessageType = IPCMessage.SymbolNotFound,
                        Message     = ServerConstants.SYMBOL_NOT_FOUND
                    };
                    results = _serializer.Serialize(notFound);
                }
                break;

            default:
                var defaultResult = new CommandResult
                {
                    IsInternal  = true,
                    RequestId   = request.Id,
                    MessageType = IPCMessage.NoProviderFound,
                    Message     = ServerConstants.NO_PROVIDER_FOUND
                };
                results = _serializer.Serialize(defaultResult);
                break;
            }

            return(results);
        }