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

refactor(language-service): temporarily remove references codeLens #4364

Merged
merged 1 commit into from
May 10, 2024

Conversation

johnsoncodehk
Copy link
Member

CSS classes, template slots references codeLens no longer works since 2.0, in order to support it again we need to add a find references request for the TS plugin's name piped server, I currently have trouble finding the time to implement it, so we have temporarily removed references codeLens.

When re-implementing in the future, the following language service plugin will be needed.

import type { LanguageServicePlugin, LanguageServicePluginInstance } from '@volar/language-service';
import { VueVirtualCode } from '@vue/language-core';
import type * as vscode from 'vscode-languageserver-protocol';

export function create(): LanguageServicePlugin {
	return {
		name: 'vue-codelens-references',
		create(context): LanguageServicePluginInstance {
			return {

				provideReferencesCodeLensRanges(document) {

					const decoded = context.decodeEmbeddedDocumentUri(document.uri);
					const sourceScript = decoded && context.language.scripts.get(decoded[0]);
					const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);

					if (sourceScript?.generated?.root instanceof VueVirtualCode && virtualCode?.id.startsWith('style_')) {

						const result: vscode.Range[] = [];
						const styleIndex = parseInt(virtualCode.id.split('_')[1]);
						const style = sourceScript.generated.root.sfc.styles[styleIndex];

						for (const className of style.classNames) {
							const start = document.positionAt(className.offset);
							const end = document.positionAt(className.offset + className.text.length);
							result.push({
								start,
								end,
							});
						}

						return result;
					}
				},
			};
		},
	};
}

@johnsoncodehk johnsoncodehk changed the title feat(language-service): temporarily remove references codeLens refactor(language-service): temporarily remove references codeLens May 10, 2024
@johnsoncodehk johnsoncodehk merged commit 999ff01 into master May 10, 2024
6 checks passed
@johnsoncodehk johnsoncodehk deleted the remove-references-code-lens branch May 10, 2024 04:44
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

Successfully merging this pull request may close these issues.

None yet

1 participant