Skip to content

Commit

Permalink
Allowing configuring if markdown inserts a .md when completing path…
Browse files Browse the repository at this point in the history
…s to markdown files (#174882)

Fixes #174005
  • Loading branch information
mjbvz authored Feb 21, 2023
1 parent 05abefc commit 784bbda
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
15 changes: 15 additions & 0 deletions extensions/markdown-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,21 @@
"additionalProperties": {
"type": "string"
}
},
"markdown.preferredMdPathExtensionStyle": {
"type": "string",
"default": "auto",
"markdownDescription": "%configuration.markdown.preferredMdPathExtensionStyle%",
"enum": [
"auto",
"includeExtension",
"removeExtension"
],
"markdownEnumDescriptions": [
"%configuration.markdown.preferredMdPathExtensionStyle.auto%",
"%configuration.markdown.preferredMdPathExtensionStyle.includeExtension%",
"%configuration.markdown.preferredMdPathExtensionStyle.removeExtension%"
]
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions extensions/markdown-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@
"configuration.markdown.updateLinksOnFileMove.enableForDirectories": "Enable updating links when a directory is moved or renamed in the workspace.",
"configuration.markdown.occurrencesHighlight.enabled": "Enable highlighting link occurrences in the current document.",
"configuration.markdown.copyFiles.destination": "Defines where files copied into a Markdown document should be created. This is a map from globs that match on the Markdown document to destinations.\n\nThe destinations may use the following variables:\n\n- `${documentFileName}` — The full filename of the Markdown document, for example `readme.md`.\n- `${documentBaseName}` — The basename of Markdown document, for example `readme`.\n- `${documentExtName}` — The extension of the Markdown document, for example `md`.\n- `${documentDirName}` — The name of the Markdown document's parent directory.\n- `${documentWorkspaceFolder}` — The workspace folder for the Markdown document, for examples, `/Users/me/myProject`. This is the same as `${documentDirName}` if the file is not part of in a workspace.\n- `${fileName}` — The file name of the dropped file, for example `image.png`.",
"configuration.markdown.preferredMdPathExtensionStyle": "Controls if file extensions (e.g. `.md`) are added or not for links to Markdown files. This setting is used when file paths are added by tooling such as path completions or file renames.",
"configuration.markdown.preferredMdPathExtensionStyle.auto": "For existing paths, try to maintain the file extension style. For new paths, add file extensions.",
"configuration.markdown.preferredMdPathExtensionStyle.includeExtension": "Prefer including the file extension. For example, path completions to a file named `file.md` will insert `file.md`.",
"configuration.markdown.preferredMdPathExtensionStyle.removeExtension": "Prefer removing the file extension. For example, path completions to a file named `file.md` will insert `file` without the `.md`.",
"workspaceTrust": "Required for loading styles configured in the workspace."
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type ValidateEnabled = 'ignore' | 'warning' | 'error' | 'hint';

export interface Settings {
readonly markdown: {
readonly preferredMdPathExtensionStyle: 'auto' | 'includeExtension' | 'removeExtension';

readonly occurrencesHighlight: {
readonly enabled: boolean;
};
Expand Down
18 changes: 13 additions & 5 deletions extensions/markdown-language-features/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,26 @@ export async function startServer(connection: Connection, serverConfig: {
let mdLs: md.IMdLanguageService | undefined;

connection.onInitialize((params: InitializeParams): InitializeResult => {
const configurationManager = new ConfigurationManager(connection);
const initOptions = params.initializationOptions as MdServerInitializationOptions | undefined;
const config = getLsConfiguration(initOptions ?? {});

const configurationManager = new ConfigurationManager(connection);
const mdConfig = getLsConfiguration(initOptions ?? {});

const workspace = serverConfig.workspaceFactory({ connection, config, workspaceFolders: params.workspaceFolders });
const workspace = serverConfig.workspaceFactory({ connection, config: mdConfig, workspaceFolders: params.workspaceFolders });
mdLs = md.createLanguageService({
workspace,
parser: serverConfig.parser,
logger: serverConfig.logger,
markdownFileExtensions: config.markdownFileExtensions,
excludePaths: config.excludePaths,
...mdConfig,
get preferredMdPathExtensionStyle() {
switch (configurationManager.getSettings()?.markdown.preferredMdPathExtensionStyle) {
case 'includeExtension': return md.PreferredMdPathExtensionStyle.includeExtension;
case 'removeExtension': return md.PreferredMdPathExtensionStyle.removeExtension;
case 'auto':
default:
return md.PreferredMdPathExtensionStyle.auto;
}
}
});

registerCompletionsSupport(connection, documents, mdLs, configurationManager);
Expand Down

0 comments on commit 784bbda

Please sign in to comment.