Skip to content

Latest commit

 

History

History
185 lines (149 loc) · 4.13 KB

text_document.md

File metadata and controls

185 lines (149 loc) · 4.13 KB

Events about files and their content.

These commands don't have response as they are like notifications/events, they define context of completions requests. We don't wait for any response from them.

didOpen, didClose, and didFocus are important because basic Github Copilot method to detect file's context - is by opened tabs(aka opened files). So these methods directly affect file's context and the quality of completions.

File opened

command = "textDocument/didOpen"

Request

Type:

{
  "textDocument": {
    "uri": "String",          // VirtualFileUri uri
    "languageId": "String",   // languageId
    "version": "Integer",     // version
    "text": "String"          // text
  } // TextDocumentItem textDocument
}

Example:

{
    "textDocument": {
        "uri": "file:///home/username/my_project/my_file.js",
        "languageId": "javascript",
        "version": 120,
        "text": "function addTwo(a, b) {\n\n}"
    }
}

Details

File closed

E.g. close tab in IDEA.

command = "textDocument/didClose"

Request

Type:

{
  "textDocument": {
    "uri": "String"  // VirtualFileUri uri
  }  // TextDocumentIdentifier textDocument
}

Example:

{
    "textDocument": {
        "uri": "file:///home/username/my_project/my_file.js"
    }
}

File changed

After text is updated in a file. While typing in JetBrains it sent on every keypress.

command = "textDocument/didChange"

Request

Type:

{
  "textDocument": {
    "uri": "String",         // VirtualFileUri uri
    "version": "Integer"     // version
  }, // VersionedTextDocumentIdentifier textDocument
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": "Integer",      // line
          "character": "Integer"  // character
        }, // Position start
        "end": {
          "line": "Integer",      // line
          "character": "Integer"  // character
        }    // Position end
      },  // Range range
      "text": "String"    // String text
    }
  ] // List<TextDocumentContentChangeEvent> contentChanges
}

Example for addition(paste):

{
    "textDocument": {
        "uri": "file:///home/username/my_project/my_file.js",
        "version": 124
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 1,
                    "character": 1
                },
                "end": {
                    "line": 1,
                    "character": 1
                }
            },
            "text": "return 1+1"
        }
    ]
}

Example for delete selection:

{
    "textDocument": {
        "uri": "file:///home/username/my_project/my_file.js",
        "version": 123
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 1,
                    "character": 1
                },
                "end": {
                    "line": 1,
                    "character": 8
                }
            },
            "text": ""
        }
    ]
}

Details

  • range.start / range.end - much likely for editing a selection.

File focused

When a tab with file is changed. It affects which files will be included in the context, as only the last 20 are selected. And from these 20 - not all of their content will be included to the prompt(maybe it also takes last access time into account?) Neighbor files are sorted based on then last access time, which is set when files is focused.

command = "textDocument/didFocus"

Request

Type:

{
  "uri": "String"   // VirtualFileUri uri
}

Example:

{
    "uri": "file:///home/username/my_project/my_file.js"
}