microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.8.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/debuggingConfiguration/launchJsonCompletionProvider.ts

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