Skip to content

Commit

Permalink
Hook up new markdown workspace header suggestion setting (microsoft#1…
Browse files Browse the repository at this point in the history
…74004)

Fixes microsoft#172977

Also fixes the settingsTree matching settings ids too eagerly
  • Loading branch information
mjbvz authored and c-claeys committed Feb 16, 2023
1 parent 6a5f1d1 commit 26d3360
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
16 changes: 16 additions & 0 deletions extensions/markdown-language-features/package.json
Expand Up @@ -401,6 +401,22 @@
"description": "%configuration.markdown.suggest.paths.enabled.description%",
"scope": "resource"
},
"markdown.suggest.paths.includeWorkspaceHeaderCompletions": {
"type": "string",
"default": "onDoubleHash",
"scope": "resource",
"markdownDescription": "%configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions%",
"enum": [
"never",
"onDoubleHash",
"onSingleOrDoubleHash"
],
"markdownEnumDescriptions": [
"%configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.never%",
"%configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.onDoubleHash%",
"%configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.onSingleOrDoubleHash%"
]
},
"markdown.trace.extension": {
"type": "string",
"enum": [
Expand Down
4 changes: 4 additions & 0 deletions extensions/markdown-language-features/package.nls.json
Expand Up @@ -31,6 +31,10 @@
"configuration.markdown.links.openLocation.currentGroup": "Open links in the active editor group.",
"configuration.markdown.links.openLocation.beside": "Open links beside the active editor.",
"configuration.markdown.suggest.paths.enabled.description": "Enable path suggestions while writing links in Markdown files.",
"configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions": "Enable suggestions for headers in other Markdown files in the current workspace. Accepting one of these suggestions inserts the full path to header in that file, for example `[link text](/path/to/file.md#header)`.",
"configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.never": "Disable workspace header suggestions.",
"configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.onDoubleHash": "Enable workspace header suggestions after typing `##` in a path, for example `[link text](##`.",
"configuration.markdown.suggest.paths.includeWorkspaceHeaderCompletions.onSingleOrDoubleHash": "Enable workspace header suggestions after typing either `##` or `#` in a path, for example `[link text](#` or `[link text](##`.",
"configuration.markdown.editor.drop.enabled": "Enable dropping files into a Markdown editor while holding Shift. Requires enabling `#editor.dropIntoEditor.enabled#`.",
"configuration.markdown.editor.pasteLinks.enabled": "Enable pasting files into a Markdown editor inserts Markdown links. Requires enabling `#editor.experimental.pasteActions.enabled#`.",
"configuration.markdown.validate.enabled.description": "Enable all error reporting in Markdown files.",
Expand Down
Expand Up @@ -17,6 +17,7 @@ export interface Settings {
readonly suggest: {
readonly paths: {
readonly enabled: boolean;
readonly includeWorkspaceHeaderCompletions: 'never' | 'onSingleOrDoubleHash' | 'onDoubleHash';
};
};

Expand Down
14 changes: 13 additions & 1 deletion extensions/markdown-language-features/server/src/server.ts
Expand Up @@ -283,6 +283,15 @@ function registerCompletionsSupport(
ls: md.IMdLanguageService,
config: ConfigurationManager,
): IDisposable {
function getIncludeWorkspaceHeaderCompletions(): md.IncludeWorkspaceHeaderCompletions {
switch (config.getSettings()?.markdown.suggest.paths.includeWorkspaceHeaderCompletions) {
case 'onSingleOrDoubleHash': return md.IncludeWorkspaceHeaderCompletions.onSingleOrDoubleHash;
case 'onDoubleHash': return md.IncludeWorkspaceHeaderCompletions.onDoubleHash;
case 'never':
default: return md.IncludeWorkspaceHeaderCompletions.never;
}
}

connection.onCompletion(async (params, token): Promise<lsp.CompletionItem[]> => {
const settings = config.getSettings();
if (!settings?.markdown.suggest.paths.enabled) {
Expand All @@ -292,7 +301,10 @@ function registerCompletionsSupport(
const document = documents.get(params.textDocument.uri);
if (document) {
// TODO: remove any type after picking up new release with correct types
return ls.getCompletionItems(document, params.position, { ...params.context!, includeWorkspaceHeaderCompletions: md.IncludeWorkspaceHeaderCompletions.onDoubleHash, } as any, token);
return ls.getCompletionItems(document, params.position, {
...(params.context || {}),
includeWorkspaceHeaderCompletions: getIncludeWorkspaceHeaderCompletions(),
} as any, token);
}
return [];
});
Expand Down
Expand Up @@ -2048,7 +2048,7 @@ function cleanRenderedMarkdown(element: Node): void {
}

function fixSettingLinks(text: string, linkify = true): string {
return text.replace(/`#([^#]*)#`|'#([^#]*)#'/g, (match, backticksGroup, quotesGroup) => {
return text.replace(/`#([^#\s`]+)#`|'#([^#\s']+)#'/g, (match, backticksGroup, quotesGroup) => {
const settingKey: string = backticksGroup ?? quotesGroup;
const targetDisplayFormat = settingKeyToDisplayFormat(settingKey);
const targetName = `${targetDisplayFormat.category}: ${targetDisplayFormat.label}`;
Expand Down

0 comments on commit 26d3360

Please sign in to comment.