Add basic markdown link completions

For #140602

Only normal links for now. Will add reference links later. Should support the forms:

- `[](dir/file.md)`
- `[](./dir/file.md)`
- `[](/root-dir/file.md)`
- `[](#header)`
- `[](./dir/file.md#header)`
This commit is contained in:
Matt Bierner
2022-01-12 18:12:51 -08:00
parent 351aa03df4
commit a4e529c759
11 changed files with 366 additions and 38 deletions

View File

@@ -3,6 +3,31 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as os from 'os';
import * as vscode from 'vscode';
import { InMemoryDocument } from './inMemoryDocument';
export const joinLines = (...args: string[]) =>
args.join(os.platform() === 'win32' ? '\r\n' : '\n');
export const noopToken = new class implements vscode.CancellationToken {
_onCancellationRequestedEmitter = new vscode.EventEmitter<void>();
onCancellationRequested = this._onCancellationRequestedEmitter.event;
get isCancellationRequested() { return false; }
};
export const CURSOR = '$$CURSOR$$';
export function getCursorPositions(contents: string, doc: InMemoryDocument): vscode.Position[] {
let positions: vscode.Position[] = [];
let index = 0;
let wordLength = 0;
while (index !== -1) {
index = contents.indexOf(CURSOR, index + wordLength);
if (index !== -1) {
positions.push(doc.positionAt(index));
}
wordLength = CURSOR.length;
}
return positions;
}