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

Feat: implement webview to the api docs as go to definition #496

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

uxkjaer
Copy link
Member

@uxkjaer uxkjaer commented Sep 12, 2022

2022-09-12_20-31-33 (2)

@lgtm-com
Copy link

lgtm-com bot commented Sep 12, 2022

This pull request introduces 3 alerts when merging aaf056e into 9d0c89c - view on LGTM.com

new alerts:

  • 3 for Unused variable, import, function or class

@bd82
Copy link
Member

bd82 commented Sep 29, 2022

Hi @uxkjaer

I am a bit conflicted about this feature:

Pros:

  • it is quite cool
  • and may be useful.

Cons:

  • It is not quite the regular "go to definition" behavior I am used to as it does not navigate to source code.
    It feels more like it is "go to docs" which is already implemented when you hover and then click on "more-information".
  • So we have a bit of duplicate feature, (go-to-docs) which is implemented in two different ways (browser redirect vs webview inside vscode).

@petermuessig WDYT?

I think I should also consult with the product person responsible for this.

@uxkjaer
Copy link
Member Author

uxkjaer commented Sep 29, 2022

My take on it.

  • youis often needs to read the api and check something.
  • The hover scroll down and click isn't really useful for me.
  • we currently don't have any other useful use case for the go to definition in an XML view
  • further possibilities are:
  • to pick up where there cursor is placed ie event or aggregation and handle deep navigation
  • implement a go to samples option as well. This could be maybe implementations.

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.

@bd82
Copy link
Member

bd82 commented Sep 29, 2022

Good points I will setup a meeting with you and the relevant product person 👍

@marianfoo
Copy link

Hi Jacob,
I think this is a good solution.
There is already a similar plugin from Jacek:
https://marketplace.visualstudio.com/items?itemName=jacek-wozniczak.vscode-ui5-api-reference
I tried this plugin and personally I prefer to have a separate browser window.
But that could also have to do with the fact that it was formatted differently here.

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.
But maybe it is well implemented and I will use it :)

@vobu
Copy link

vobu commented Sep 30, 2022

just also wanted to bring up @wozjac's extension.
and there is also a .docset from @monavari-lebrecht at http://monavari.de/docset/ .
sooo...in best Ghostbuster's style 👻, why not combine the streams and ...

  • incorporate @wozjac's extension here, into the language assistant itself (and award him eternal fame)
  • provide an option to export to .docset, taking up @monavari-lebrecht's work
  • have @uxkjaer's API ref in the webview as a "read more"-link of sorts, being available from the incorporated @wozjac's extension

@uxkjaer
Copy link
Member Author

uxkjaer commented Oct 1, 2022

We could also consider just using a custom menu option and command instead, if that makes more sense?

@bd82
Copy link
Member

bd82 commented Oct 1, 2022

We could also consider just using a custom menu option and command instead, if that makes more sense?

Perhaps:

  • Would it ever make sense to ever implement a go-to-definition that would open the source code of UI5?
  • So if we keep it as currently implemented would it conflict with such a future feature?

I am generally in favor of this (or similar) feature, But it a major feature and I'd like to demonstrate it to the
relevant product person, but with the holidays season in Israel now, this will add some delay...

@uxkjaer
Copy link
Member Author

uxkjaer commented Oct 2, 2022

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.
We could also have another one for going to samples.

Happy to discuss this with relevant people.

@uxkjaer
Copy link
Member Author

uxkjaer commented Oct 12, 2022

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.

@lgtm-com
Copy link

lgtm-com bot commented Oct 12, 2022

This pull request introduces 1 alert when merging 37f9155 into 90807cd - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@uxkjaer
Copy link
Member Author

uxkjaer commented Oct 19, 2022

closes #495

@uxkjaer uxkjaer linked an issue Oct 19, 2022 that may be closed by this pull request
@@ -25,6 +25,13 @@ export type ServerInitializationOptions = {
logLevel?: LogLevel;
};

export function getNodeName(
Copy link
Member

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

Copy link
Member

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,
Copy link
Member

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
Copy link
Member

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(
Copy link
Member

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> {
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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(
Copy link
Member

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,
Copy link
Member

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:
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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",
Copy link
Member

@bd82 bd82 Oct 27, 2022

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?

@bd82
Copy link
Member

bd82 commented Oct 27, 2022

Does the ui5 logo belong in this PR?

});

function getXmlSnippet(
Copy link
Member

@bd82 bd82 Oct 27, 2022

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");
Copy link
Member

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) {
Copy link
Member

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"
Copy link
Member

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() {
Copy link
Member

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) {
Copy link
Member

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 : ""}`;
Copy link
Member

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() {
Copy link
Member

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

@bd82
Copy link
Member

bd82 commented Oct 27, 2022

I think we need to review this in a "pair programing" session.
I get the feeling this PR has broken some assumptions on the code structure in this mono-repo.
But I am a bit rusty in regards to this project...

@cla-assistant
Copy link

cla-assistant bot commented Oct 18, 2023

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link

cla-assistant bot commented Oct 18, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant
Copy link

cla-assistant bot commented Oct 18, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

Implement go to definition
4 participants