Skip to content

Commit

Permalink
Merge pull request #1230 from YusukeHirao/features/v4/#794
Browse files Browse the repository at this point in the history
Add hover options to VS Code settings
  • Loading branch information
YusukeHirao authored Oct 20, 2023
2 parents 1612d62 + 620aebd commit ca97f6f
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 49 deletions.
3 changes: 2 additions & 1 deletion vscode/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"NodeJS": true
},
"rules": {
"no-restricted-globals": 0
"no-restricted-globals": 0,
"unicorn/prefer-module": 0
},
"overrides": [
{
Expand Down
4 changes: 2 additions & 2 deletions vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
- `markuplint.debug`: Enable debug mode
- `markuplint.defaultConfig`: It's the configuration specified if configuration files do not exist
- `markuplint.targetLanguages`: Specify the target languages
- `markuplint.showAccessibility`: Enable the feature that **popup Accessibility Object**
- `markuplint.showAccessibility.ariaVersion`: Set `1.1` or `1.2` WAI-ARIA version; Default is `1.2`.
- `markuplint.hover.accessibility.enable`: Enable the feature that **popup Accessibility Object**
- `markuplint.hover.accessibility.ariaVersion`: Set `1.1` or `1.2` WAI-ARIA version; Default is `1.2`.

## Release Notes

Expand Down
14 changes: 14 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@
"markuplint:recommended"
]
}
},
"markuplint.hover.accessibility.enable": {
"type": "boolean",
"markdownDescription": "Enable the feature that **popup Accessibility Object**",
"default": true
},
"markuplint.hover.accessibility.ariaVersion": {
"type": "string",
"markdownDescription": "Set `1.1` or `1.2` WAI-ARIA version; Default is `1.2`.",
"enum": [
"1.1",
"1.2"
],
"default": "1.2"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import path from 'node:path';
import { window, workspace, StatusBarAlignment, commands } from 'vscode';
import { RevealOutputChannelOn, LanguageClient, TransportKind } from 'vscode-languageclient/node';

import { Logger } from './Logger';
import { StatusBar } from './StatusBar';
import {
COMMAND_NAME_OPEN_LOG_COMMAND,
ID,
OUTPUT_CHANNEL_PRIMARY_CHANNEL_NAME,
OUTPUT_CHANNEL_DIAGNOSTICS_CHANNEL_NAME,
WATCHING_CONFIGURATION_GLOB,
} from './const';
import { Logger } from './logger';
import {
configs,
errorToPopup,
Expand All @@ -25,6 +24,7 @@ import {
status,
warningToPopup,
} from './lsp';
import { StatusBar } from './status-bar';

let client: LanguageClient;

Expand Down
2 changes: 1 addition & 1 deletion vscode/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getLocaleSet(langCode: string): LocaleSet {
if (loadLocaleSet) {
return loadLocaleSet;
}
} catch (_) {
} catch {
// Avoid
}
return require('../locales/en.json');
Expand Down
1 change: 1 addition & 0 deletions vscode/src/Logger.ts → vscode/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class Logger {
this.#channel.clear();
break;
}
// eslint-disable-next-line unicorn/no-useless-switch-case
case 'info':
default: {
this.#channel.info(message);
Expand Down
8 changes: 3 additions & 5 deletions vscode/src/server/document-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,14 @@ export function createEventHandlers(
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
params: HoverParams,
) {
const showAccessibility = options.langConfigs['html']?.showAccessibility ?? true;
const enable = options.langConfigs['html']?.hover.accessibility.enable;

if (showAccessibility === false) {
if (!enable) {
return;
}

const ariaVersion =
typeof showAccessibility === 'boolean'
? options.mod.ariaRecommendedVersion
: showAccessibility.ariaVersion;
options.langConfigs['html']?.hover.accessibility.ariaVersion ?? options.mod.ariaRecommendedVersion;

if (options.mod.type === 'v4') {
const aria = await v4.getNodeWithAccessibilityProps(params.textDocument, params.position, ariaVersion);
Expand Down
14 changes: 7 additions & 7 deletions vscode/src/server/get-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ export async function getModule(baseDir: string, log: Log): Promise<OldModule |
modPath,
ariaRecommendedVersion: '1.2',
};
} catch (_e) {
} catch {
try {
require('markuplint');
} catch (e) {
if (e && typeof e === 'object' && 'code' in e) {
switch (e.code) {
} catch (error) {
if (error && typeof error === 'object' && 'code' in error) {
switch (error.code) {
case 'ERR_PACKAGE_PATH_NOT_EXPORTED': {
if ('message' in e && typeof e.message === 'string') {
const matched = /^No "exports" main defined in (.+)\/package\.json$/i.exec(e.message);
if ('message' in error && typeof error.message === 'string') {
const matched = /^no "exports" main defined in (.+)\/package\.json$/i.exec(error.message);
log(`Found package as ESM: ${matched?.[1]}`, 'debug');
}
}
}
} else {
throw e;
throw error;
}
}

Expand Down
1 change: 1 addition & 0 deletions vscode/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function bootServer() {
});

documents.onDidOpen(e => onDidOpen(e.document));
// eslint-disable-next-line unicorn/no-array-for-each
documents.all().forEach(onDidOpen);

documents.onDidChangeContent(e => onDidChangeContent(e.document));
Expand Down
8 changes: 4 additions & 4 deletions vscode/src/server/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function onDidOpen(

console.log('exec (onDidOpen)');

engine.exec().catch((e: unknown) => notFoundParserError(e));
engine.exec().catch((error: unknown) => notFoundParserError(error));
}

let debounceTimer: NodeJS.Timer;
Expand All @@ -112,9 +112,9 @@ export function onDidChangeContent(
try {
await engine.setCode(code);
console.log('exec (onDidChangeContent)');
engine.exec().catch((e: unknown) => notFoundParserError(e));
} catch (e) {
console.log(e);
engine.exec().catch((error: unknown) => notFoundParserError(error));
} catch (error) {
console.log(error);
// continue;
}
}, 300);
Expand Down
18 changes: 9 additions & 9 deletions vscode/src/server/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ export async function onDidOpen(

log('Run `engine.exec()` in `onDidOpen`', 'debug');

engine.exec().catch((e: unknown) => {
log(String(e), 'error');
notFoundParserError(e);
throw e;
engine.exec().catch((error: unknown) => {
log(String(error), 'error');
notFoundParserError(error);
throw error;
});
}

Expand All @@ -152,13 +152,13 @@ export function onDidChangeContent(
try {
await engine.setCode(code);
log('Run `engine.exec()` in `onDidChangeContent`', 'debug');
engine.exec().catch((e: unknown) => notFoundParserError(e));
} catch (e: unknown) {
if (e instanceof Error) {
log(e.message, 'error');
engine.exec().catch((error: unknown) => notFoundParserError(error));
} catch (error: unknown) {
if (error instanceof Error) {
log(error.message, 'error');
return;
}
log(`UnknownError: ${e}`, 'error');
log(`UnknownError: ${error}`, 'error');
}
}, 300);
}
Expand Down
22 changes: 11 additions & 11 deletions vscode/src/server/v4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ export async function onDidOpen(

log('Run `engine.exec()` in `onDidOpen`', 'debug');

engine.exec().catch((e: unknown) => {
log(String(e), 'error');
notFoundParserError(e);
throw e;
engine.exec().catch((error: unknown) => {
log(String(error), 'error');
notFoundParserError(error);
throw error;
});
}

Expand All @@ -164,13 +164,13 @@ export function onDidChangeContent(
try {
await engine.setCode(code);
log('Run `engine.exec()` in `onDidChangeContent`', 'debug');
engine.exec().catch((e: unknown) => notFoundParserError(e));
} catch (e: unknown) {
if (e instanceof Error) {
log(e.message, 'error');
engine.exec().catch((error: unknown) => notFoundParserError(error));
} catch (error: unknown) {
if (error instanceof Error) {
log(error.message, 'error');
return;
}
log(`UnknownError: ${e}`, 'error');
log(`UnknownError: ${error}`, 'error');
}
}, 300);
}
Expand Down Expand Up @@ -221,10 +221,10 @@ export async function getNodeWithAccessibilityProps(
: `${t('None')}${aria.nameRequired ? ` ${requiredLabel}` : ''}`;
labels.focusable = `\`${aria.focusable}\``;

Object.entries(aria.props ?? {}).forEach(([propName, { value, required }]) => {
for (const [propName, { value, required }] of Object.entries(aria.props ?? {})) {
labels[propName] =
value === undefined ? t('Undefined') + (required ? ` ${requiredLabel}` : '') : `\`${value}\``;
});
}

return {
nodeName: node,
Expand Down
File renamed without changes.
11 changes: 6 additions & 5 deletions vscode/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ export type Config = {
enable: boolean;
debug: boolean;
defaultConfig: MLConfig;
showAccessibility:
| boolean
| {
ariaVersion: ARIAVersion;
};
hover: {
accessibility: {
enable: boolean;
ariaVersion: ARIAVersion;
};
};
};

export type Status = {
Expand Down
1 change: 1 addition & 0 deletions vscode/src/utils/deferred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class Deferred<T = undefined> implements PromiseLike<T> {
this.#resolve(value);
}

// eslint-disable-next-line unicorn/no-thenable
then<TResult1 = T, TResult2 = never>(
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
Expand Down
4 changes: 2 additions & 2 deletions vscode/src/utils/get-file-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export function getFilePath(uri: string, langId: string) {
const decodePath = fileURLToPath(decodeURIComponent(uri));
let filePath: string;
let untitled = false;
if (/^file:/.test(decodePath)) {
if (decodePath.startsWith('file:')) {
filePath = decodePath.replace(/^file:\/+/i, '/');
} else if (/^untitled:/.test(decodePath)) {
} else if (decodePath.startsWith('untitled:')) {
filePath = decodePath.replace(/^untitled:/i, '');
untitled = true;
} else {
Expand Down

0 comments on commit ca97f6f

Please sign in to comment.