microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fix-ts-error1

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/launchJsonCompletionProvider.ts

66lines · modecode

1// 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";
5import * as vscode from "vscode";
6import { getLocation } from "jsonc-parser";
7import * as nls from "vscode-nls";
8
9nls.config({
10 messageFormat: nls.MessageFormat.bundle,
11 bundleFormat: nls.BundleFormat.standalone,
12})();
13const localize = nls.loadMessageBundle();
14
15export enum JsonLanguages {
16 json = "json",
17 jsonWithComments = "jsonc",
18}
19
20export class LaunchJsonCompletionProvider implements vscode.CompletionItemProvider {
21 private readonly configurationNodeName = "configurations";
22
23 public provideCompletionItems(
24 document: vscode.TextDocument,
25 position: vscode.Position,
26 token: vscode.CancellationToken,
27 // eslint-disable-next-line @typescript-eslint/no-unused-vars
28 context: vscode.CompletionContext,
29 ): vscode.ProviderResult<vscode.CompletionItem[] | vscode.CompletionList> {
30 if (!this.canProvideCompletions(document, position)) {
31 return [];
32 }
33
34 return [
35 {
36 command: {
37 command: "reactNative.selectAndInsertDebugConfiguration",
38 title: localize(
39 "SelectReactNativeDebugConfiguration",
40 "Select a React Native debug configuration",
41 ),
42 arguments: [document, position, token],
43 },
44 documentation: localize(
45 "SelectReactNativeDebugConfiguration",
46 "Select a React Native debug configuration",
47 ),
48 sortText: "AAAA",
49 preselect: true,
50 kind: vscode.CompletionItemKind.Enum,
51 label: "React Native",
52 insertText: new vscode.SnippetString(),
53 },
54 ];
55 }
56
57 private canProvideCompletions(document: vscode.TextDocument, position: vscode.Position) {
58 if (path.basename(document.uri.fsPath) !== "launch.json") {
59 return false;
60 }
61 const 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.
64 return location.path[0] === this.configurationNodeName && location.path.length === 2;
65 }
66}
67