Add support for extensionless Python files for server (#13326)

## Summary

Closes: #12539 

## Test Plan

https://github.com/user-attachments/assets/e49b2669-6f12-4684-9e45-a3321b19b659
This commit is contained in:
Dhruv Manilawala 2024-09-12 00:35:26 +05:30 committed by GitHub
parent eded78a39b
commit b72d49be16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 57 additions and 4 deletions

View file

@ -20,6 +20,23 @@ pub struct TextDocument {
/// The latest version of the document, set by the LSP client. The server will panic in
/// debug mode if we attempt to update the document with an 'older' version.
version: DocumentVersion,
/// The language ID of the document as provided by the client.
language_id: Option<LanguageId>,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum LanguageId {
Python,
Other,
}
impl From<&str> for LanguageId {
fn from(language_id: &str) -> Self {
match language_id {
"python" => Self::Python,
_ => Self::Other,
}
}
}
impl TextDocument {
@ -29,9 +46,16 @@ impl TextDocument {
contents,
index,
version,
language_id: None,
}
}
#[must_use]
pub fn with_language_id(mut self, language_id: &str) -> Self {
self.language_id = Some(LanguageId::from(language_id));
self
}
pub fn into_contents(self) -> String {
self.contents
}
@ -48,6 +72,10 @@ impl TextDocument {
self.version
}
pub fn language_id(&self) -> Option<LanguageId> {
self.language_id
}
pub fn apply_changes(
&mut self,
changes: Vec<lsp_types::TextDocumentContentChangeEvent>,