Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Vine/Server/Notification/
RegisterLanguageProvider.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Handles all `register_*` / `register_*_provider` gRPC notifications from
4//! the Cocoon extension host. Each such notification wires a language-feature
5//! provider into Mountain's `ProviderRegistration` keyed on `Handle`; the
6//! language-feature RPC path (e.g. `GetHoverAtPosition`) then proxies back to
7//! Cocoon with the original `$providerXxx` method.
8//!
9//! Wire-method naming uses snake_case with two trailing shapes:
10//! - plain verbs:     `register_rename`, `register_debug_adapter`
11//! - `_provider` suffix: `register_hover_provider`,
12//!   `register_code_lens_provider`
13//!
14//! Both forms are normalised by stripping `register_` prefix and optional
15//! `_provider` suffix before the enum lookup.
16
17use CommonLibrary::LanguageFeature::DTO::ProviderType::ProviderType as PT;
18use serde_json::{Value, json};
19
20use crate::{
21	ApplicationState::DTO::ProviderRegistrationDTO::ProviderRegistrationDTO,
22	Vine::Server::MountainVinegRPCService::MountainVinegRPCService,
23	dev_log,
24};
25
26/// Dispatch a `register_*` notification. Returns `true` if the method was
27/// recognised and a `ProviderRegistrationDTO` was inserted.
28pub async fn RegisterLanguageProvider(Service:&MountainVinegRPCService, MethodName:&str, Parameter:&Value) -> bool {
29	let Handle = Parameter.get("handle").and_then(|h| h.as_u64()).unwrap_or(0) as u32;
30
31	// Accept camelCase (current Cocoon shape) with snake_case fallback for
32	// partial rebuild compatibility.
33	let Selector = Parameter
34		.get("languageSelector")
35		.or_else(|| Parameter.get("language_selector"))
36		.and_then(|s| s.as_str())
37		.unwrap_or("*");
38	let ExtId = Parameter
39		.get("extensionId")
40		.or_else(|| Parameter.get("extension_id"))
41		.and_then(|e| e.as_str())
42		.unwrap_or("");
43	let Scheme = Parameter.get("scheme").and_then(|s| s.as_str()).unwrap_or("");
44
45	let ProviderTypeName = MethodName
46		.strip_prefix("register_")
47		.map(|Stripped| Stripped.strip_suffix("_provider").unwrap_or(Stripped))
48		.unwrap_or("");
49
50	dev_log!(
51		"grpc-verbose",
52		"[MountainVinegRPCService] Cocoon registered {} provider: handle={}, lang={}",
53		ProviderTypeName,
54		Handle,
55		Selector
56	);
57	dev_log!(
58		"provider-register",
59		"[ProviderRegister] accepted method={} type={} handle={} lang={} scheme={} ext={}",
60		MethodName,
61		ProviderTypeName,
62		Handle,
63		Selector,
64		Scheme,
65		ExtId
66	);
67
68	let ProvType:Option<PT> = match ProviderTypeName {
69		"authentication" => Some(PT::Authentication),
70		"call_hierarchy" => Some(PT::CallHierarchy),
71		"code_actions" => Some(PT::CodeAction),
72		"code_lens" => Some(PT::CodeLens),
73		"color" => Some(PT::Color),
74		"completion_item" => Some(PT::Completion),
75		"debug_adapter" => Some(PT::DebugAdapter),
76		"debug_configuration" => Some(PT::DebugConfiguration),
77		"declaration" => Some(PT::Declaration),
78		"definition" => Some(PT::Definition),
79		"document_drop_edit" => Some(PT::DocumentDropEdit),
80		"document_formatting" => Some(PT::DocumentFormatting),
81		"document_highlight" => Some(PT::DocumentHighlight),
82		"document_link" => Some(PT::DocumentLink),
83		"document_paste_edit" => Some(PT::DocumentPasteEdit),
84		"document_range_formatting" => Some(PT::DocumentRangeFormatting),
85		"document_symbol" => Some(PT::DocumentSymbol),
86		"evaluatable_expression" => Some(PT::EvaluatableExpression),
87		"external_uri_opener" => Some(PT::ExternalUriOpener),
88		"file_decoration" => Some(PT::FileDecoration),
89		"file_system" => Some(PT::FileSystem),
90		"folding_range" => Some(PT::FoldingRange),
91		"hover" => Some(PT::Hover),
92		"implementation" => Some(PT::Implementation),
93		"inlay_hints" => Some(PT::InlayHint),
94		"inline_completion_item" => Some(PT::InlineCompletion),
95		"inline_edit" => Some(PT::InlineEdit),
96		"inline_values" => Some(PT::InlineValues),
97		"linked_editing_range" => Some(PT::LinkedEditingRange),
98		"mapped_edits" => Some(PT::MappedEdits),
99		"multi_document_highlight" => Some(PT::MultiDocumentHighlight),
100		"notebook_content" => Some(PT::NotebookContent),
101		"notebook_serializer" => Some(PT::NotebookSerializer),
102		"on_type_formatting" => Some(PT::OnTypeFormatting),
103		"reference" => Some(PT::References),
104		"remote_authority_resolver" => Some(PT::RemoteAuthorityResolver),
105		"rename" => Some(PT::Rename),
106		"resource_label_formatter" => Some(PT::ResourceLabelFormatter),
107		"scm" => Some(PT::SourceControl),
108		"scm_resource_group" => Some(PT::ScmResourceGroup),
109		"selection_range" => Some(PT::SelectionRange),
110		"semantic_tokens" => Some(PT::SemanticTokens),
111		"signature_help" => Some(PT::SignatureHelp),
112		"task" => Some(PT::Task),
113		"terminal_link" => Some(PT::TerminalLink),
114		"terminal_profile" => Some(PT::TerminalProfile),
115		"text_document_content" => Some(PT::TextDocumentContent),
116		"type_definition" => Some(PT::TypeDefinition),
117		"type_hierarchy" => Some(PT::TypeHierarchy),
118		"uri_handler" => Some(PT::UriHandler),
119		"workspace_symbol" => Some(PT::WorkspaceSymbol),
120		_ => None,
121	};
122
123	let Some(ProviderType) = ProvType else { return false };
124
125	// Scheme-bound providers carry their scheme in the selector so Mountain's
126	// resolver (FileSystem router, URI handler dispatch, …) can match on it.
127	let SelectorValue = if !Scheme.is_empty() {
128		json!([{ "scheme": Scheme, "language": Selector }])
129	} else {
130		json!([{ "language": Selector }])
131	};
132
133	let Dto = ProviderRegistrationDTO {
134		Handle,
135		ProviderType,
136		Selector:SelectorValue,
137		SideCarIdentifier:"cocoon-main".to_string(),
138		ExtensionIdentifier:json!(ExtId),
139		Options:Parameter.get("options").cloned(),
140	};
141
142	Service
143		.RunTime()
144		.Environment
145		.ApplicationState
146		.Extension
147		.ProviderRegistration
148		.RegisterProvider(Handle, Dto);
149
150	true
151}