Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does it Use Open Tabs? Needs documentation #211

Open
pha3z opened this issue Oct 5, 2024 · 6 comments
Open

Does it Use Open Tabs? Needs documentation #211

pha3z opened this issue Oct 5, 2024 · 6 comments

Comments

@pha3z
Copy link

pha3z commented Oct 5, 2024

One of the big R&D points over the past couple of years on the use of Copilot is how to make Copilot better at understanding the context of your local repo. Its critical to using it as efficiently as possible.

In VS Code and Visual Studio, out-of-the-box, the Copilot extensions give high priority on Open Tabs as input for context. LSP-copilot does not mention whether Open Tabs --or even your local folders-- have an impact on context.

It would be nice if this were documented. Can we at least get an answer on this post?

@jfcherng
Copy link
Collaborator

jfcherng commented Oct 5, 2024

Some facts...

  • We are using the LSP server from Copilot.vim.
  • The LSP server is not open sourced and it has no doc (literally none). @TerminalFi did some reverse engineering to make it work here.

@pha3z
Copy link
Author

pha3z commented Oct 5, 2024

Ahh.. I had to go do some reading to get educated on language servers. I see now why this is non-trivial.

Just out of curiosity, have you seen this project? I discovered it from digging around on language servers.
https://github.com/SilasMarvin/lsp-ai

@pha3z
Copy link
Author

pha3z commented Oct 5, 2024

I found this
https://stackoverflow.com/a/77659136/1402498
and this
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/

These shed light on the fact that Copilot's awareness is dependent on the didOpen, didClose, and didChange invocations to the LSP. This is how, as the IDE/editor client, you would notify the LSP about open tabs.

@jfcherng
Copy link
Collaborator

jfcherng commented Oct 5, 2024

Theoretically, when a project is open, the language server instance will be initiated. It will know the project path. So theoretically, it can do what it want to do with the whole project without didXxx notification from the client. It can depend on didXxx too for sure.

But since it's not open sourced and there is no doc, we can only either guess by its behaviors (can it provide good suggestion without other files in the project being opened?) or reverse engineer it.

@jfcherng
Copy link
Collaborator

jfcherng commented Oct 5, 2024

Just out of curiosity, have you seen this project? I discovered it from digging around on language servers.
SilasMarvin/lsp-ai

Yes it was posted on ST Discord server before. But I think the real issue is ST's APIs can only provide quite limited UX.

@TerminalFi
Copy link
Owner

@pha3z Copilot gets all of the regular LSP notifications. Its context is also driven by References that are included on every "turn" message you send to Copilot. We have a very simple implementation, that mirrors the majority of Copilot in VSCode for what we can emulate,

references: list[CopilotRequestConversationTurnReference | CopilotGitHubWebSearch] = []
visible_range = st_region_to_lsp_range(view.visible_region(), view)
views.append(view)
for view_ in views:
if not (selection := view_.sel()[0]) or view_.substr(selection).isspace():
continue
references.append({
"type": "file",
"status": "included", # included, blocked, notfound, empty
"uri": filename_to_uri(file_path) if (file_path := view_.file_name()) else f"buffer:{view.buffer().id()}",
"position": st_point_to_lsp_position(selection.begin(), view_),
"range": st_region_to_lsp_range(selection, view),
"visibleRange": visible_range,
"selection": st_region_to_lsp_range(selection, view_),
"openedAt": None,
"activeAt": None,
})

There is definitely improvements that can be made. However this is very much a hobby of @jfcherng and myself. @timfjord contributed initially as well however his time is also focused else where for the most part.

I am currently more focus on projects which may generate revenue at this point.

However, I have spoken to the VP over the Copilot team a few months...6-9 months now I guess and Github/M$ does plan on releasing a SDK / Documentation. However, when / if that happens has yet to be seen.

Until then, I encourage the community to reverse the current implementations out there and contribute back to this plugin if they indeed want to see it become more feature complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants