[fidl][lsp] Move gen_fidl_project.py to fuchsia.git

Change-Id: I722a6e0efb0567a41142729a6c449dc50771bd44
Reviewed-on: https://fuchsia-review.googlesource.com/c/fidl-misc/+/397773
Reviewed-by: Benjamin Prosnitz <bprosnitz@google.com>
diff --git a/fidl-lsp/README.md b/fidl-lsp/README.md
index 42af390..54102e2 100644
--- a/fidl-lsp/README.md
+++ b/fidl-lsp/README.md
@@ -9,12 +9,13 @@
 
 1. Follow the [Fuchsia: Get Started](https://fuchsia.dev/fuchsia-src/getting_started)
    guide.
-2. Build fidl-lint: `fx build host_x64/fidl-lint`.
-3. Ensure that you have [Go](https://golang.org/) and [Node.js](https://nodejs.org/)
+2. Run `fx gen` to make sure `fidl_project.json` exists.
+3. Build fidl-lint: `fx build host_x64/fidl-lint`.
+4. Ensure that you have [Go](https://golang.org/) and [Node.js](https://nodejs.org/)
    installed.
-4. Fetch prebuilts and compile the language server and VSCode extension by
+5. Fetch prebuilts and compile the language server and VSCode extension by
    running `build-vscode.sh`.
-5. Open the `fidl-misc/vscode-language-fidl/` directory in VSCode, and run the
+6. Open the `fidl-misc/vscode-language-fidl/` directory in VSCode, and run the
    `Launch Extension` task.
 
 If you want to use local versions of fidlc and fidl-format instead of the latest
@@ -41,14 +42,18 @@
 
 ### `langserver` package
 
-This package includes the core logic of the language server. It deals with LSP specific boilerplate, JSON-RPC messages, etc. It includes the `LangHandler`
+This package includes the core logic of the language server. It deals with LSP
+specific boilerplate, JSON-RPC messages, etc. It includes the `LangHandler`
 type, which handles LSP requests, sends reponses and notifications to the
-client, and dispatches changes to the state manager or requests for analyses to the `Analyzer`.
+client, and dispatches changes to the state manager or requests for analyses to
+the `Analyzer`.
 
 ### `state` package
 
-The language server's state management is in the `state` package. Currently this is just an in memory file system (mapping of editor file names to file text).
-This could be wrapped in e.g. an `RWLock` to enable concurrent handling of LSP requests and notifications.
+The language server's state management is in the `state` package. Currently this
+is just an in memory file system (mapping of editor file names to file text).
+This could be wrapped in e.g. an `RWLock` to enable concurrent handling of LSP
+requests and notifications.
 
 ### `analysis` package
 
@@ -57,14 +62,17 @@
 
 Includes the `Analyzer` type, which maintains a set of compiled FIDL `Library`s
 and their constituent files, dependencies, and build artifacts. Main entry point
-is `Analyzer.Analyze()`, which is called every time a file is changed on the client. `Analyze` recompiles the relevant FIDL library for that file and imports  the JSON IR.
+is `Analyzer.Analyze()`, which is called every time a file is changed on the
+client. `Analyze` recompiles the relevant FIDL library for that file and imports
+the JSON IR.
 
 The `Analyzer` compiles FIDL libraries by invoking `fidlc` in a separate
 process, gets diagnostics from `fidlc` and `fidl-lint`, and uses `fidl-format`
 for formatting. It locates dependencies using a `fidl_project.json` file, the
-path to which will be configurable in the LSP client extension. `fidl_project.json` declares all FIDL libraries the language server should be aware
-of, the paths to their constituent files, the path to their JSON IR,
-and their dependencies (by library name).
+path to which will be configurable in the LSP client extension. `fidl_project.json`
+declares all FIDL libraries the language server should be aware of, the paths to
+their constituent files, the path to their JSON IR, and their dependencies (by
+library name).
 
 ## Supported LSP features
 
diff --git a/fidl-lsp/scripts/gen_fidl_project.py b/fidl-lsp/scripts/gen_fidl_project.py
deleted file mode 100644
index ebd2bd3..0000000
--- a/fidl-lsp/scripts/gen_fidl_project.py
+++ /dev/null
@@ -1,105 +0,0 @@
-#!/usr/bin/env python3
-# Copyright 2020 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-"""
-generate fidl_project.json file declaring FIDL libraries
-
-This script reads the all_fidl_generated.json file which contains all fidlgen- &
-fidlc-generated output, and generates a fidl_project.json file which declares
-all FIDL libraries along with their constituent files, dependencies, and build
-artifacts (JSON IR and bindings). This is for use in the FIDL Language Server,
-which uses fidl_project to do dependency resolution.
-
-This script makes the assumption that all FIDL library names are unique, which
-is currently not the case. However, the exceptions are mainly test libraries, so
-for now this is left unaddressed.
-"""
-import glob
-import json
-import os
-import re
-import sys
-from pathlib import Path
-
-FUCHSIA_DIR = os.getenv('FUCHSIA_DIR')
-ALL_FIDL_GENERATED_PATH = 'out/default/all_fidl_generated.json'
-
-# schema:
-# map<string, Library>
-# where string is library name e.g. 'fuchsia.mem'
-# and Library is
-# {
-#     "files": []string,
-#     "json": string,
-#     "deps": []string,
-#     "bindings": {
-#         "hlcpp": {},
-#         "llcpp": {},
-#         "rust": {},
-#         "go": {},
-#         "dart": {},
-#         ...
-#     }
-# }
-
-
-def find_files(artifact):
-    library_name = artifact['library']
-    pattern = f'^fidling\/gen\/([\w\.\/-]+)\/[\w\-. ]+\.fidl\.json$'
-    result = re.search(pattern, artifact['files'][0])
-    if not result or not result.group(1):
-        return []
-
-    fidl_dir = Path(f'{FUCHSIA_DIR}/{result.group(1)}')
-    globs = [
-        fidl_dir.glob('*.fidl'),
-        fidl_dir.parent.glob('*.fidl'),
-    ]
-
-    files = []
-    for glob in globs:
-        for file in glob:
-            # TODO: read in file
-            # parse `library` decl
-            # check that it matches library name
-            files.append(str(file))
-    return files
-
-
-def find_deps(artifact):
-    library_json = artifact['files'][0]
-    library_json_path = Path(f'{FUCHSIA_DIR}/out/default/{library_json}')
-    with open(library_json_path, 'r') as f:
-        library = json.load(f)
-        deps = library['library_dependencies']
-        deps = [dep['name'] for dep in deps]
-        return deps
-
-
-def gen_fidl_project(fidl_project_path):
-    result = {}
-
-    all_fidl_path = FUCHSIA_DIR + '/' + ALL_FIDL_GENERATED_PATH
-    with open(all_fidl_path, 'r') as f:
-        artifacts = json.load(f)
-
-    print('have read in all_fidl_generated')
-    print(len(artifacts))
-
-    for artifact in artifacts:
-        if artifact['type'] == 'json':
-            result[artifact['library']] = {
-                'json': f"{FUCHSIA_DIR}/out/default/{artifact['files'][0]}",
-                'files': find_files(artifact),
-                'deps': find_deps(artifact),
-                'bindings': {},  # TODO
-            }
-
-    print('writing to {}', fidl_project_path)
-    with open(fidl_project_path, 'w') as f:
-        json.dump(result, f, indent=4, sort_keys=True)
-
-
-if __name__ == '__main__':
-    gen_fidl_project(sys.argv[1])