MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / createPlugin

Function createPlugin

src/cm/lsp/inlayHints.ts:135–274  ·  view source on GitHub ↗
(config: InlayHintsConfig)

Source from the content-addressed store, hash-verified

133// ============================================================================
134
135function createPlugin(config: InlayHintsConfig) {
136 const delay = config.debounceMs ?? 200;
137 const max = config.maxHints ?? 500;
138 const showTypes = config.showTypes !== false;
139 const showParams = config.showParameters !== false;
140
141 return ViewPlugin.fromClass(
142 class {
143 decorations: DecorationSet = Decoration.none;
144 timer: ReturnType<typeof setTimeout> | null = null;
145 reqId = 0;
146
147 constructor(private view: EditorView) {
148 this.fetch();
149 }
150
151 update(update: ViewUpdate): void {
152 if (
153 update.transactions.some((t) => t.effects.some((e) => e.is(setHints)))
154 ) {
155 this.decorations = buildDecos(
156 update.state.field(hintsField, false) ?? [],
157 update.state.doc.length,
158 );
159 }
160 if (update.docChanged || update.viewportChanged) {
161 this.schedule();
162 }
163 }
164
165 schedule(): void {
166 if (this.timer) clearTimeout(this.timer);
167 this.timer = setTimeout(() => {
168 this.timer = null;
169 this.fetch();
170 }, delay);
171 }
172
173 async fetch(): Promise<void> {
174 const lsp = LSPPlugin.get(this.view) as LSPPluginAPI | null;
175 if (!lsp?.client.connected) return;
176
177 const caps = lsp.client.serverCapabilities;
178 if (!caps?.inlayHintProvider) return;
179
180 lsp.client.sync();
181 const id = ++this.reqId;
182 const doc = this.view.state.doc;
183
184 // Visible range with buffer
185 const { from, to } = this.view.viewport;
186 const buf = 20;
187 const startLn = Math.max(1, doc.lineAt(Math.max(0, from)).number - buf);
188 const endLn = Math.min(
189 doc.lines,
190 doc.lineAt(Math.min(doc.length, to)).number + buf,
191 );
192

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected