-
Notifications
You must be signed in to change notification settings - Fork 46
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
feat: add reference and definition provider #145
base: main
Are you sure you want to change the base?
Conversation
How can I use them? |
): languages.ProviderResult<languages.Definition | languages.LocationLink[]> { | ||
const resource = model.uri; | ||
const lineContent = model.getLineContent(position.lineNumber); | ||
if (lineContent.startsWith('--')) return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是否还要考虑块级注释
/* DROP TABLE IF EXISTS aabb; */
-- DROP TABLE IF EXISTS aabb;
DROP TABLE IF EXISTS aabb;
@@ -197,3 +201,85 @@ export class CompletionAdapter<T extends BaseSQLWorker> | |||
}); | |||
} | |||
} | |||
|
|||
export class DefinitionAdapter<T extends BaseSQLWorker> implements languages.DefinitionProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看下两个 Provider 要不要加下注释
src/languageFeatures.ts
Outdated
if (!lineContent.startsWith('CREATE')) return null; | ||
return this._worker(resource) | ||
.then((worker) => { | ||
return worker.getAllEntities(model.getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code 需要用 preprocessCode 处理,原因参考 #60
另一个 provider 同
src/setupLanguageMode.ts
Outdated
@@ -34,6 +34,18 @@ export function setupLanguageMode<T extends BaseSQLWorker>( | |||
) | |||
); | |||
} | |||
providers.push( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
考虑是否支持配置为关闭此功能,参考已有的自动补全功能和代码飘红功能,都是可以关闭的
.then((entities) => { | ||
const word = model.getWordAtPosition(position); | ||
const arr: languages.Location[] = []; | ||
entities?.forEach((entity) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
考虑是否支持外部自定义跳转位置,另一个provider同
deploy website到自己的仓库上,让review的人可以预览 |
@Cythia828 将 |
|
540687d
to
59a541e
Compare
59a541e
to
ee61c06
Compare
feat
需要注意
Shift+F12
,但由于大家的使用习惯是Command+click
,所以需要关注下当你在 Monaco Editor 中配置 references 为 true 而 definitions 为 false 时,Command + Click (或 Ctrl + Click) 无法跳转到引用,这是因为 Monaco Editor 的默认行为是:Command + Click 主要用于跳转到 定义 (definitions),而不是引用 (references)。 即使你启用了 references 功能,Command + Click 仍然优先处理 DefinitionProvider,因为它被设计为跳转到定义的快捷方式。
ReferenceProvider 提供的是“查找所有引用”的功能,这通常通过右键菜单或自定义命令来触发,而不是 Command + Click。 Command + Click 的行为是由 Monaco Editor 的核心功能决定的,它与 ReferenceProvider 和 DefinitionProvider 的启用状态之间没有直接的逻辑关联。 Command + Click 始终优先尝试跳转到定义,只有当 DefinitionProvider 无法提供定义时,它才可能尝试其他行为。
常规使用跳转到定义、引用功能时,我们都是配套打开的,此时,我们通过Command + Click 可以进行跳转到定义和引用。通常不会只打开跳转到引用,而不打开跳转到定义。如果只打开跳转到引用,而不打开跳转到定义,那么我们通过 右键唤起菜单跳到引用,通过选择某一个具体引用进行跳转,这个操作也是流畅且合理的。
预览地址
https://cythia828.github.io/monaco-sql-languages/