Clean up after syntax migration

This CL reverts the auto-convert feature that was temporarily added in
I4e4f33f177860be8db7a139b9d81192e0bca7d1e for the new FIDL syntax, since
this no longer works as of the cleanup in fxrev.dev/574026. It leaves
the "news" abstraction since we can reuse this in the future.

Change-Id: I27b7c54363a3864693cbdb8143bc4588b25553f3
Reviewed-on: https://fuchsia-review.googlesource.com/c/fidlbolt/+/579181
Reviewed-by: Yifei Teng <yifeit@google.com>
diff --git a/backend/server.go b/backend/server.go
index 3d6f2e3..470ab8c 100644
--- a/backend/server.go
+++ b/backend/server.go
@@ -7,6 +7,7 @@
 import (
 	"context"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -165,7 +166,7 @@
 	Offsets bool `json:"offsets"`
 	// Show ASCII characters at the end of lines like xxd.
 	ASCII bool `json:"ascii"`
-	// Convert FIDL from old to new (RFC-0050) syntax.
+	// Deprecated: Convert FIDL from old to new (RFC-0050) syntax.
 	ConvertSyntax bool `json:"convertSyntax"`
 }
 
@@ -252,6 +253,10 @@
 		return err
 	}
 
+	if r.Options.ConvertSyntax {
+		return errors.New("convertSyntax is no longer supported")
+	}
+
 	switch r.OutputMode {
 	case JSON:
 		switch r.Options.File {
@@ -365,7 +370,6 @@
 			msg := fmt.Sprintf("%s:1:1: error: %s", fidl, err)
 			return response{Ok: false, Content: msg}, nil
 		}
-		args = append(args, "--experimental", "allow_new_syntax")
 		run, err := s.fidlc.run(ctx, append(args, fileArgs...)...)
 		if err != nil {
 			return response{}, err
@@ -391,20 +395,6 @@
 
 	switch r.OutputMode {
 	case FIDL:
-		if r.Options.ConvertSyntax {
-			res, err := fidlc("--convert-syntax", temp.path)
-			if err != nil {
-				return response{}, err
-			}
-			if !res.Ok {
-				return res, nil
-			}
-			res.Content, err = temp.readFile("fidlbolt.fidl.new")
-			if err != nil {
-				return response{}, err
-			}
-			return res, err
-		}
 		prog := s.fidlFormat
 		if r.Options.Lint {
 			prog = s.fidlLint
diff --git a/frontend/src/elm/Editors.elm b/frontend/src/elm/Editors.elm
index 6d123c1..2be7153 100644
--- a/frontend/src/elm/Editors.elm
+++ b/frontend/src/elm/Editors.elm
@@ -11,7 +11,6 @@
     , encode
     , init
     , initCmd
-    , subscriptions
     , update
     , view
     )
@@ -46,7 +45,6 @@
 type alias Model =
     { activeInput : Mode
     , inputMap : Mode.Map InputState
-    , fidlSyntax : FidlSyntax
     }
 
 
@@ -72,11 +70,6 @@
     }
 
 
-type FidlSyntax
-    = UnknownSyntax
-    | OldSyntax
-
-
 init : Model
 init =
     let
@@ -88,7 +81,6 @@
     in
     { activeInput = input
     , inputMap = Mode.singleton input inputState
-    , fidlSyntax = UnknownSyntax
     }
 
 
@@ -164,10 +156,6 @@
     | ActivateOutput Mode
       -- Update options for the current input/output mode combination.
     | UpdateOptions Form.Msg
-      -- Assume FIDL input is using the given syntax.
-    | AssumeSyntax FidlSyntax
-      -- Tell the evaluator to convert to the new FIDL syntax.
-    | ConvertSyntax
 
 
 update : Msg -> Model -> ( Model, Cmd msg )
@@ -187,23 +175,11 @@
                 UpdateOptions formMsg ->
                     updateOptions (Form.update formMsg) model
 
-                AssumeSyntax syntax ->
-                    { model | fidlSyntax = syntax }
-
-                ConvertSyntax ->
-                    model
-
         cmd =
             case msg of
                 NoOp ->
                     Cmd.none
 
-                AssumeSyntax _ ->
-                    Cmd.none
-
-                ConvertSyntax ->
-                    Ports.convertToNewSyntax
-
                 _ ->
                     updateEditors (getActive newModel)
     in
@@ -288,15 +264,6 @@
 
 
 
-------------- SUBSCRIPTIONS ----------------------------------------------------
-
-
-subscriptions : Sub Msg
-subscriptions =
-    Ports.syntaxDetected NoOp (Decode.map AssumeSyntax decodeFidlSyntax)
-
-
-
 ------------- VIEW -------------------------------------------------------------
 
 
@@ -318,13 +285,7 @@
                     , activeMode = active.input
                     , msg = ActivateInput
                     , id = "InputEditor"
-                    , optionsPart =
-                        case ( active.input, model.fidlSyntax ) of
-                            ( Mode.Fidl, OldSyntax ) ->
-                                [ convertToNewSyntaxView toMsg ]
-
-                            _ ->
-                                []
+                    , optionsPart = []
                     }
 
                 Output ->
@@ -398,25 +359,6 @@
         ]
 
 
-convertToNewSyntaxView : (Msg -> msg) -> Html msg
-convertToNewSyntaxView toMsg =
-    Html.div
-        [ Attributes.class "editor-options" ]
-        [ Html.div [ Attributes.class "form-control" ]
-            [ Html.text "Looks like you are using the "
-            , Html.a
-                [ Attributes.href News.newSyntax2021Url ]
-                [ Html.text "old FIDL syntax" ]
-            , Html.text "."
-            , Html.button
-                [ Attributes.class "button form-button"
-                , Events.onClick (toMsg ConvertSyntax)
-                ]
-                [ Html.text "Convert to new syntax" ]
-            ]
-        ]
-
-
 keyDownEvent : Editor -> Active -> (Msg -> msg) -> Decode.Decoder msg
 keyDownEvent editor active toMsg =
     let
@@ -478,10 +420,9 @@
 
 decode : Decode.Decoder Model
 decode =
-    Decode.map3 Model
+    Decode.map2 Model
         (Decode.field "activeInput" Mode.decode)
         (Decode.field "inputMap" (Mode.decodeMap decodeInputState))
-        (Decode.succeed UnknownSyntax)
 
 
 decodeInputState : Decode.Decoder InputState
@@ -495,20 +436,3 @@
 decodeOutputState =
     Decode.map OutputState
         (Decode.field "options" Form.decode)
-
-
-decodeFidlSyntax : Decode.Decoder FidlSyntax
-decodeFidlSyntax =
-    Decode.string
-        |> Decode.andThen
-            (\string ->
-                case string of
-                    "unknown" ->
-                        Decode.succeed UnknownSyntax
-
-                    "old" ->
-                        Decode.succeed OldSyntax
-
-                    _ ->
-                        Decode.fail ("Invalid syntax name: " ++ string)
-            )
diff --git a/frontend/src/elm/Main.elm b/frontend/src/elm/Main.elm
index 452cad0..c7cd869 100644
--- a/frontend/src/elm/Main.elm
+++ b/frontend/src/elm/Main.elm
@@ -255,7 +255,6 @@
 subscriptions model =
     Sub.batch
         [ Sub.map DeploymentMsg Deployment.subscriptions
-        , Sub.map EditorMsg Editors.subscriptions
         , Sub.map SplitMsg (SplitPane.subscriptions model.split)
         , Sub.map WindowMsg (Window.subscriptions model.window)
         ]
diff --git a/frontend/src/elm/Ports.elm b/frontend/src/elm/Ports.elm
index 88c0378..1e1a7c3 100644
--- a/frontend/src/elm/Ports.elm
+++ b/frontend/src/elm/Ports.elm
@@ -6,12 +6,10 @@
 port module Ports exposing
     ( applySettings
     , clearDataAndReload
-    , convertToNewSyntax
     , deploymentUpdated
     , persistModel
     , resizeEditors
     , setMainTabEnabled
-    , syntaxDetected
     , updateEditors
     )
 
@@ -75,11 +73,6 @@
     command "resizeEditors" Encode.null
 
 
-convertToNewSyntax : Cmd msg
-convertToNewSyntax =
-    command "convertToNewSyntax" Encode.null
-
-
 
 ------------- INCOMING ---------------------------------------------------------
 
@@ -117,8 +110,3 @@
 deploymentUpdated : msg -> Decode.Decoder msg -> Sub msg
 deploymentUpdated =
     subscribe "deploymentUpdated"
-
-
-syntaxDetected : msg -> Decode.Decoder msg -> Sub msg
-syntaxDetected =
-    subscribe "syntaxDetected"
diff --git a/frontend/src/evaluator.ts b/frontend/src/evaluator.ts
index 53f3415..c48902c 100644
--- a/frontend/src/evaluator.ts
+++ b/frontend/src/evaluator.ts
@@ -13,13 +13,6 @@
 // milliseconds. This should be at least as long as the CSS .loader transition.
 const LOADER_DISPLAY_NONE_DELAY = 300;
 
-// Regexes for FIDL errors that likely indicate the user is writing the old
-// syntax and fidlc is attempting to parse the new syntax.
-const OLD_FIDL_SYNTAX_ERROR_REGEXES = [
-  /^fidlbolt.fidl:\d+:\d+: error: invalid declaration type (?:bits|enum|struct|table|union|strict|flexible|resource|)/,
-  /^fidlbolt.fidl:\d+:\d+: error: unexpected token Identifier, was expecting RightParen/,
-];
-
 // A request sent to the server.
 interface Request {
   inputMode: InputMode;
@@ -49,10 +42,6 @@
 // to specify its fields here because we just forward it to Elm.
 type Deployment = object;
 
-// FIDL syntax is detected as 'old' if compilation fails due to an error in
-// OLD_FIDL_SYNTAX_ERROR_REGEXES and conversion to the new syntax succeeds.
-type FidlSyntax = 'unknown' | 'old';
-
 // Evaluator sends requests to the server to update the output.
 export class Evaluator {
   readonly editors: Editors;
@@ -64,9 +53,7 @@
   lastInput: InputMap;
   active?: Omit<Request, 'content'>;
   loaderTimeout?: Timeout;
-  syntaxConversionResult?: string;
   deploymentCallback?: (deployment: Deployment) => void;
-  syntaxCallback?: (syntax: FidlSyntax) => void;
 
   constructor(editors: Editors, saveFn: VoidFunction) {
     this.editors = editors;
@@ -77,19 +64,13 @@
     this.stopFn = undefined;
     this.loaderElement = document.getElementById('Loader') as HTMLElement;
     this.loaderTimeout = undefined;
-    this.syntaxConversionResult = undefined;
     this.deploymentCallback = undefined;
-    this.syntaxCallback = undefined;
   }
 
   onDeloymentUpdated(callback: (deployment: Deployment) => void) {
     this.deploymentCallback = callback;
   }
 
-  onSyntaxDetected(callback: (syntax: FidlSyntax) => void) {
-    this.syntaxCallback = callback;
-  }
-
   setActive(inputMode: InputMode, outputMode: OutputMode, options: Options) {
     this.active = {inputMode, outputMode, options};
   }
@@ -186,7 +167,6 @@
       return;
     }
 
-    this.resetSyntaxConversion();
     this.startLoadingAnimation();
     const finish = (
       content: string,
@@ -205,17 +185,6 @@
         error
       );
       this.endLoadingAnimation();
-
-      if (
-        request.inputMode === 'fidl' &&
-        error === 'Error' &&
-        // If the input includes "deprecated_syntax;", then fidlc should
-        // recognize it as old syntax and conversion is unnecessary.
-        !request.content.includes('deprecated_syntax;') &&
-        OLD_FIDL_SYNTAX_ERROR_REGEXES.some(re => re.test(content))
-      ) {
-        this.tryOfferingSyntaxConversion(request.content);
-      }
     };
 
     this.saveFn();
@@ -256,71 +225,6 @@
     }
   }
 
-  resetSyntaxConversion() {
-    if (this.syntaxConversionResult != undefined) {
-      this.syntaxConversionResult = undefined;
-      if (this.syntaxCallback != undefined) {
-        this.syntaxCallback('unknown');
-      }
-    }
-  }
-
-  // Try converting fidlContent to the new FIDL syntax and offer it to the user
-  // on a best-effort basis (nothing user-visible happens if it fails).
-  async tryOfferingSyntaxConversion(fidlContent: string) {
-    let response;
-    try {
-      response = await withTimeout(
-        POST_REQUEST_TIMEOUT,
-        'Timed out waiting for server to respond',
-        fetch('/convert', {
-          method: 'POST',
-          headers: {'Content-Type': 'application/json'},
-          body: JSON.stringify({
-            inputMode: 'fidl',
-            outputMode: 'fidl',
-            options: {convertSyntax: true},
-            content: 'deprecated_syntax;\n' + fidlContent,
-          }),
-        })
-      );
-    } catch (error) {
-      return;
-    }
-    if (!response.ok) {
-      return;
-    }
-    const json = await response.json();
-    if (!json.ok) {
-      return;
-    }
-    if (this.syntaxCallback != undefined) {
-      this.syntaxConversionResult = json.content;
-      this.syntaxCallback('old');
-    }
-  }
-
-  convertToNewSyntax() {
-    const result = this.syntaxConversionResult;
-    this.resetSyntaxConversion();
-    if (
-      this.active == undefined ||
-      this.active.inputMode != 'fidl' ||
-      result == undefined
-    ) {
-      return;
-    }
-    const request = {
-      ...this.active,
-      content: this.editors.inputEditor.getValue(),
-    };
-    if (this.needsRefresh(request)) {
-      // The FIDL has changed since we converted it.
-      return;
-    }
-    this.editors.inputEditor.setValue(result);
-  }
-
   startLoadingAnimation() {
     clearTimeout(this.loaderTimeout);
     this.loaderElement.style.display = 'block';
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 714e383..cf9dd6e 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -50,12 +50,6 @@
       payload: deployment,
     });
   });
-  evaluator.onSyntaxDetected(syntax => {
-    app.ports.fromJS.send({
-      command: 'syntaxDetected',
-      payload: syntax,
-    });
-  });
 
   app.ports.toJS.subscribe(({command, payload}: ElmMessage) => {
     switch (command) {
@@ -109,10 +103,6 @@
         });
         break;
       }
-      case 'convertToNewSyntax': {
-        evaluator.convertToNewSyntax();
-        break;
-      }
     }
   });