Skip to content

Commit 487f7d3

Browse files
committed
feat(apidom-ls): add 'follow link' to hover for URL like strings
1 parent 5812bd4 commit 487f7d3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/apidom-ls/src/apidom-language-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export interface LanguageSettings {
215215
logLevel?: LogLevel;
216216
defaultContentLanguage?: ContentLanguage;
217217
workspaceFolders?: WorkspaceFolder[];
218+
hoverFollowLinkEntry?: boolean;
218219
}
219220

220221
// export type SeverityLevel = 'error' | 'warning' | 'ignore';

packages/apidom-ls/src/services/hover/hover-service.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import {
2525
debug,
2626
} from '../../utils/utils';
2727

28+
const CONTROL_CODES = '\\u0000-\\u0020\\u007f-\\u009f';
29+
const WEB_LINK_REGEX = new RegExp(
30+
`(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\\/\\/|data:|www\\.)[^\\s${CONTROL_CODES}"]{2,}[^\\s${CONTROL_CODES}"')}\\],:;.!?]`,
31+
'ug',
32+
);
33+
2834
export interface HoverService {
2935
computeHover(textDocument: TextDocument, position: Position): Promise<Hover | undefined>;
3036

@@ -272,6 +278,14 @@ export class DefaultHoverService implements HoverService {
272278
} catch (e) {
273279
console.log('error in hover provider');
274280
}
281+
} else if (this.settings?.hoverFollowLinkEntry) {
282+
// check if we have a "URL like" value, and add a link in case
283+
const nodeValue = node.toValue();
284+
// if (/^https?:\/\/[^\s]+.*/.test(nodeValue)) {
285+
if (WEB_LINK_REGEX.test(nodeValue)) {
286+
contents.push(`[follow link](${nodeValue})`);
287+
// TODO no ctrl-click on link
288+
}
275289
}
276290
}
277291
try {

0 commit comments

Comments
 (0)