-
Notifications
You must be signed in to change notification settings - Fork 27
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: implement webview to the api docs as go to definition #496
base: master
Are you sure you want to change the base?
Conversation
uxkjaer
commented
Sep 12, 2022
This pull request introduces 3 alerts when merging aaf056e into 9d0c89c - view on LGTM.com new alerts:
|
Hi @uxkjaer I am a bit conflicted about this feature: Pros:
Cons:
@petermuessig WDYT? I think I should also consult with the product person responsible for this. |
My take on it.
I know we aren't navigating source code, but we don't have any other useful use case for these options. We could simply add our own as well and a different short cut. My idea was that you were already used to the f12 shortcut to go and read a definition. |
Good points I will setup a meeting with you and the relevant product person 👍 |
Hi Jacob, But you are right, I didn't know the function of "more information". I think the use case of Jakob is a good one and can help nicely, even if I probably won't use it. |
just also wanted to bring up @wozjac's extension.
|
We could also consider just using a custom menu option and command instead, if that makes more sense? |
Perhaps:
I am generally in favor of this (or similar) feature, But it a major feature and I'd like to demonstrate it to the |
We have types for openui5 and Sapui5 so maybe navigate to those instead? Happy to just add this as another menu option instead. Mainly I'm just keen to get a possibility not to leave vscode when needing to search the api. Happy to discuss this with relevant people. |
I've changed the shortcut and context menu to UI5-Language-Assistant: View API Reference. The go to definition no longer shows the api reference. I've also added a setting with options to either show API reference inside vscode or in browser. |
This pull request introduces 1 alert when merging 37f9155 into 90807cd - view on LGTM.com new alerts:
|
closes #495 |
@@ -25,6 +25,13 @@ export type ServerInitializationOptions = { | |||
logLevel?: LogLevel; | |||
}; | |||
|
|||
export function getNodeName( |
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.
why does the language server exposes a logical utility function?
It generally runs in a different process and communicates via JSON_RPC
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.
Generally the language server should use logical utilities from other packages.
Maybe getNodeName should be extracted out of the language server sub-package.
@@ -25,6 +25,13 @@ export type ServerInitializationOptions = { | |||
logLevel?: LogLevel; | |||
}; | |||
|
|||
export function getNodeName( | |||
text: string, |
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.
with so many arguments, some of which are optional you should probably use a config object in this case.
framework, | ||
ui5Version | ||
); | ||
return ui5Node |
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.
I think too much is done here in a single expression.
Can you split this up into multiple statements for readability?
@@ -108,3 +113,30 @@ export function getNodeDetail(node: BaseUI5Node): string { | |||
return node.name; | |||
} | |||
} | |||
|
|||
export async function getUI5NodeName( |
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.
I am not sure this function belongs in this sub-package
cachePath?: string, | ||
framework?: string, | ||
ui5Version?: string | ||
): Promise<BaseUI5Node | undefined> { |
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.
with so many params and optional params a config object may be warranted
} | ||
|
||
async function fetchModel(cachePath, framework, ui5Version) { | ||
const ui5Model = await getSemanticModel(cachePath, framework, ui5Version); |
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.
I do not recall:
Does every functional flow invoke getSemanticModel
?
Or does it happen once on language server startup?
Is this different or the same as other functional flows?
ui5Version?: string | ||
): Promise<BaseUI5Node | undefined> { | ||
const documentText = text; | ||
const { cst, tokenVector } = parse(documentText); |
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.
Again I do not recall.
Does every flow functional flow re-parses the text each time?
Or is there a cache of documents / CST?
import { track } from "./swa"; | ||
|
||
export function getHoverResponse( | ||
export async function getHoverResponse( |
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.
could changing this to async
break anything?
@@ -128,6 +130,7 @@ connection.onCompletion( | |||
minUI5Version | |||
); | |||
connection.sendNotification("UI5LanguageAssistant/ui5Model", { | |||
cachePath: initializationOptions?.modelCachePath, |
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.
why does this feature require adding the cache path to the notifications?
Perhaps I am rusty in regards to this code base, but why was it not needed for other features, but needed here?
@@ -8841,11 +8841,6 @@ tr46@^1.0.1: | |||
dependencies: |
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.
why did the lock file change if no changes were made to the package.json?
export type Settings = CodeAssistSettings & | ||
TraceSettings & | ||
LoggingSettings & | ||
API_Reference; |
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.
The naming of API_Reference
type does not seem consistent
with the existing pattern in this code base / file
browser: true; | ||
} | ||
|
||
export const validViewApiReferenceValues: IValidApiReferenceValues; |
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.
remove view
from the name to have consistent type
and const
names?
@@ -124,6 +124,16 @@ The feature is available in the following: | |||
|
|||
![](https://raw.githubusercontent.com/SAP/ui5-language-assistant/master/packages/vscode-ui5-language-assistant/resources/readme/preview-manifest-json.gif) | |||
|
|||
### Quick navigation to API Reference | |||
|
|||
Right click a tag in the XML file and use the View API reference shortcut to navigate directly to the API reference. Use the setting |
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.
Creating a demo GIF for this feature may be a good idea to "publicize" it.
"UI5LanguageAssistant.view.API_Reference": "browser" | "editor" | ||
``` | ||
|
||
The default setting is editor which opens the API reference in a new editor to the side. |
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.
clearer explanation needed.
editor
settings is described by the same word "editor"- "browser" flow is not described.
@@ -124,6 +124,16 @@ The feature is available in the following: | |||
|
|||
![](https://raw.githubusercontent.com/SAP/ui5-language-assistant/master/packages/vscode-ui5-language-assistant/resources/readme/preview-manifest-json.gif) | |||
|
|||
### Quick navigation to API Reference | |||
|
|||
Right click a tag in the XML file and use the View API reference shortcut to navigate directly to the API reference. Use the setting |
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.
View API reference --> View API Reference
@@ -20,6 +20,29 @@ | |||
"*" | |||
], | |||
"contributes": { | |||
"commands": [ | |||
{ | |||
"command": "UI5LanguageAssistant.command.webView", |
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.
is webView
the correct term for the command?
Or is this an implementation detail of one of the two possible implementation?
Does the ui5 logo belong in this PR? |
}); | ||
|
||
function getXmlSnippet( |
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.
are these two utility test functions copy / pasted from another sub-package?
"SAPUI5", | ||
ui5Model.version | ||
); | ||
if (result) expect(getNodeDetail(result)).to.equal("sap.m.Input"); |
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.
why is the test none deterministic ?
why is an if / else needed?
document.getText(), | ||
ui5SemanticModel | ||
); | ||
if (result) { |
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.
why is the test none deterministic ?
why is an if / else needed?
}); | ||
|
||
it("get the UI5 node name without a model", async () => { | ||
const xmlSnippet = `<mvc:View displayBlock="true" |
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.
these snippets normally need a "⇶" symbol to mark the cursor position.
Why is this not needed here?
@@ -125,6 +150,101 @@ function updateCurrentModel(model: UI5Model | undefined) { | |||
} | |||
} | |||
|
|||
async function showWebView() { |
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.
this logic should be in a separate file.
The "extension.ts" responsibility is for initializing the language server.
new concerns should be in a separate file.
} | ||
} | ||
|
||
function getWebviewContent(ui5Url: string) { |
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.
missing explicit return type
return undefined; | ||
}); | ||
} | ||
const ui5Url = `${new URL(apiRefUrl).href}${name ? "#/api/" + name : ""}`; |
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.
should not there be re-use in build the API ref link?
This is also done in the "more details" in hover feature...
@@ -125,6 +150,101 @@ function updateCurrentModel(model: UI5Model | undefined) { | |||
} | |||
} | |||
|
|||
async function showWebView() { |
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.
try to refactor this 70 lines function by extracting logical sub-parts
so the high level logical flow would be easily visible
I think we need to review this in a "pair programing" session. |
|
1 similar comment
|