microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.12.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/launchJsonCompletionProvider.ts

66lines · modeblame

5471436aRedMickey5 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as path from "path";
09f6024fHeniker4 years ago5import * as vscode from "vscode";
5471436aRedMickey5 years ago6import { getLocation } from "jsonc-parser";
7import * as nls from "vscode-nls";
09f6024fHeniker4 years ago8
5471436aRedMickey5 years ago9nls.config({
10messageFormat: nls.MessageFormat.bundle,
11bundleFormat: nls.BundleFormat.standalone,
12})();
13const localize = nls.loadMessageBundle();
14
15export enum JsonLanguages {
16json = "json",
17jsonWithComments = "jsonc",
18}
19
20export class LaunchJsonCompletionProvider implements vscode.CompletionItemProvider {
21private readonly configurationNodeName = "configurations";
22
23public provideCompletionItems(
24document: vscode.TextDocument,
25position: vscode.Position,
26token: vscode.CancellationToken,
228fed39RedMickey5 years ago27// eslint-disable-next-line @typescript-eslint/no-unused-vars
5471436aRedMickey5 years ago28context: vscode.CompletionContext,
29): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
30if (!this.canProvideCompletions(document, position)) {
31return [];
32}
33
34return [
35{
36command: {
37command: "reactNative.selectAndInsertDebugConfiguration",
38title: localize(
39"SelectReactNativeDebugConfiguration",
40"Select a React Native debug configuration",
41),
42arguments: [document, position, token],
43},
44documentation: localize(
45"SelectReactNativeDebugConfiguration",
46"Select a React Native debug configuration",
47),
48sortText: "AAAA",
49preselect: true,
50kind: vscode.CompletionItemKind.Enum,
51label: "React Native",
52insertText: new vscode.SnippetString(),
53},
54];
55}
56
57private canProvideCompletions(document: vscode.TextDocument, position: vscode.Position) {
58if (path.basename(document.uri.fsPath) !== "launch.json") {
59return false;
60}
61const location = getLocation(document.getText(), document.offsetAt(position));
62// Cursor must be inside the configurations array and not in any nested items.
63// Hence path[0] = array, path[1] = array element index.
64return location.path[0] === this.configurationNodeName && location.path.length === 2;
65}
66}