syntax = "proto3";


message LspPosition {
    int32 line = 1;
    int32 character = 2;
}


message LspRange {
    LspPosition start = 1;
    LspPosition end = 2;
}


message LspLocation {
    string uri = 1;
    LspRange range = 2;
}


message ImportedFrom {
    /*optional*/ LspRange statementRange = 1;
    /*optional*/ string targetUri = 2;
    /*optional*/ string targetImportPath = 3;
}


message ImportedItem {
             int32        statementId             = 1;
             string       absoluteName            = 2;
             string       localName               = 3;
             LspRange     localImportLocation     = 4;
             ImportedFrom from                    = 5;
    repeated int32        referencesTokenIndexesX = 6;
}


message AutoexposedEntity {// TODO: also CsnToken
    string absoluteName = 1;
    string kind         = 2;
    string originName   = 3;
    string originUri    = 4;
    int32 flags         = 5;
}


message Docs {
  /*optional*/ string comment     = 1;
  /*optional*/ string title       = 2;
  /*optional*/ string description = 3;
}


message BaseIdToken {// TODO: CsnToken is now compatible by fields, but we need to persist the subtype e.g. constructor's name, to be able to patch correct prototype after depersist
        // TODO: same order as BaseIdentifierInto - also all other types, to get consistent v8 classes

    string   identifierCategory = 1; // Idea: use numerical enum
    bool     isLastPathSegment  = 2;
    string   localName          = 3;
    string   absoluteName       = 4;
    string   kind               = 5; // annotations don't have kind TODO?
    string   originName         = 6;

    // IBaseDefinitionToken
    Docs     _doc               = 7;

//    string category = 8; // always 'Identifier' -> do not persist, fix in post

    string   originUri          = 9;
    LspRange definitionRange    = 10;
}


message AnnotationAssignmentToken {
    // GenericToken fields
    string   uri          = 1;
    int32    tokenIndex   = 2;
    string   text         = 3;
    int32    line         = 4;
    int32    character    = 5;

    // Proxy to the carrier token: carrier: IIdentifierToken
    int32    carrierTokenIndexX = 6;
    string   carrierName        = 7;
    LspRange carrierNameRange   = 8;
//    LspRange _range             = 9;
}


message Token {
                                            //    int32 _index = 1; // do not persist, all tokens are part of an array which defines its tokenIndex
                                            //    string _text = 2; // do not persist, Object.assign from parsed
             int32 flags = 3;
                                            //    string _cat = 4;
                                            //    int32 _line = 5;
                                            //    int32 _character = 6;
                                            //    int32 _endLine = 7;
                                            //    int32 _endCharacter = 8;
                                            //    int32 startOffset = 9;
                                            //    string uri = 10;

             BaseIdToken _id = 11;

    // IAutoexposingService
    map<string, AutoexposedEntity> autoexposedEntities = 12;

                                                    //    /*optional*/AnnotationAssignmentToken annotationAssignment = 12;
             int32 annotationAssignmentIdX  = 13;
    repeated int32 compilerMessagesIndexesX = 14;

             string translationId = 15;
}


message CodeDescription {
    string href = 1;
}


message LspDiagnosticRelatedInformation {
    LspLocation location = 1;
    string      message  = 2;
}


message LspDiagnostic {
             LspRange        range           = 1;
             int32           severity        = 2;
             string          code            = 3; // Actually number|string according to LSP spec
             CodeDescription codeDescription = 4;
             string          source          = 5;
             string          message         = 6;
    repeated int32           tags            = 7;
    repeated LspDiagnosticRelatedInformation relatedInformation = 8;
}


message FileIndex {
    repeated ImportedItem  usingStatistics               = 1;
                                                                // _statistics: IStatistics
                                                                // _diagnosticState?: DiagnosticsState;
             bool          _isInvalidByChangedContent    = 2;
             bool          _isInvalidByChangedDependency = 3;
    repeated Token         tokens                        = 4;
             string        compilerVersion               = 5;
    repeated LspDiagnostic compilerMessages              = 6;
    repeated string        directDependentUris           = 7; // TODO: this could be huge memory footprint. Q: is there a way to hook into the persistency? Or (crazy idea): keep a global map with URI -> number. But the map needs to be persisted per FileIndex! At least all uris used, and how to depersist? Other idea: hashed uris? Big drawback: debuggability!! :-/
    repeated AnnotationAssignmentToken annotationAssignmentTokens = 8; // Only during persistency instead of _annotationAssignments
    repeated LspDiagnostic _annotationDiagnostics        = 9; // TODO: stale constant
             string        uri                           = 10;
//             int32         workspaceVersion              = 11;
                                                                // _implicitDefinitions: ImplicitDefinitions;
                                                                // string content;
}