in src/cordova.ts [102:208]
export function onFolderAdded(folder: vscode.WorkspaceFolder): void {
let workspaceRoot = folder.uri.fsPath;
if (!CordovaProjectHelper.isCordovaProject(workspaceRoot)) {
vscode.window.showWarningMessage(localize("ExtensionRequiresWorkspaceRootToBeCordovaProjectRoot", "VS Code Cordova Tools extension requires the workspace root to be your Cordova project's root. The project '{0}' won't be available for debugging.", workspaceRoot));
return;
}
// Send project type to telemetry for each workspace folder
let cordovaProjectTypeEvent = TelemetryHelper.createTelemetryEvent("cordova.projectType");
TelemetryHelper.determineProjectTypes(workspaceRoot)
.then((projType) => {
cordovaProjectTypeEvent.properties["projectType"] =
TelemetryHelper.prepareProjectTypesTelemetry(projType);
})
.finally(() => {
Telemetry.send(cordovaProjectTypeEvent);
});
// We need to update the type definitions added to the project
// as and when plugins are added or removed. For this reason,
// setup a file system watcher to watch changes to plugins in the Cordova project
// Note that watching plugins/fetch.json file would suffice
let watcher = vscode.workspace.createFileSystemWatcher("**/plugins/fetch.json", false /*ignoreCreateEvents*/, false /*ignoreChangeEvents*/, false /*ignoreDeleteEvents*/);
watcher.onDidChange(() => updatePluginTypeDefinitions(workspaceRoot));
watcher.onDidDelete(() => updatePluginTypeDefinitions(workspaceRoot));
watcher.onDidCreate(() => updatePluginTypeDefinitions(workspaceRoot));
EXTENSION_CONTEXT.subscriptions.push(watcher);
let simulator: PluginSimulator = new PluginSimulator();
let workspaceManager: CordovaWorkspaceManager = new CordovaWorkspaceManager(simulator, folder);
ProjectsStorage.addFolder(folder, workspaceManager);
COUNT_WORKSPACE_FOLDERS ++;
// extensionServer takes care of disposing the simulator instance
// context.subscriptions.push(extensionServer);
const ionicMajorVersion = CordovaProjectHelper.determineIonicMajorVersion(workspaceRoot);
// In case of Ionic 1 project register completions providers for html and javascript snippets
if (ionicMajorVersion === 1) {
EXTENSION_CONTEXT.subscriptions.push(
vscode.languages.registerCompletionItemProvider(
IonicCompletionProvider.JS_DOCUMENT_SELECTOR,
new IonicCompletionProvider(path.join(findFileInFolderHierarchy(__dirname, "snippets"), "ionicJs.json"))));
EXTENSION_CONTEXT.subscriptions.push(
vscode.languages.registerCompletionItemProvider(
IonicCompletionProvider.HTML_DOCUMENT_SELECTOR,
new IonicCompletionProvider(path.join(findFileInFolderHierarchy(__dirname, "snippets"), "ionicHtml.json"))));
}
// Install Ionic type definitions if necessary
if (CordovaProjectHelper.isIonicAngularProject(workspaceRoot)) {
let ionicTypings: string[] = [
path.join("jquery", "jquery.d.ts"),
path.join("cordova-ionic", "plugins", "keyboard.d.ts"),
];
if (ionicMajorVersion === 1) {
ionicTypings = ionicTypings.concat([
path.join("angularjs", "angular.d.ts"),
path.join("ionic", "ionic.d.ts"),
]);
}
TsdHelper.installTypings(CordovaProjectHelper.getOrCreateTypingsTargetPath(workspaceRoot), ionicTypings, workspaceRoot);
}
let pluginTypings = getPluginTypingsJson();
if (!pluginTypings) {
return;
}
// Skip adding typings for cordova in case of Typescript or Ionic (except v1) projects
// to avoid conflicts between typings we install and user-installed ones.
if (!CordovaProjectHelper.isTypescriptProject(workspaceRoot) &&
!(ionicMajorVersion && ionicMajorVersion > 1)
) {
// Install the type defintion files for Cordova
TsdHelper.installTypings(CordovaProjectHelper.getOrCreateTypingsTargetPath(workspaceRoot),
[pluginTypings[CORDOVA_TYPINGS_QUERYSTRING].typingFile], workspaceRoot);
}
// Install type definition files for the currently installed plugins
updatePluginTypeDefinitions(workspaceRoot);
let pluginFilePath = path.join(workspaceRoot, ".vscode", "plugins.json");
if (fs.existsSync(pluginFilePath)) {
fs.unlinkSync(pluginFilePath);
}
TelemetryHelper.sendPluginsList(workspaceRoot, CordovaProjectHelper.getInstalledPlugins(workspaceRoot));
// In VSCode 0.10.10+, if the root doesn't contain jsconfig.json or tsconfig.json, intellisense won't work for files without /// typing references, so add a jsconfig.json here if necessary
let jsconfigPath: string = path.join(workspaceRoot, JSCONFIG_FILENAME);
let tsconfigPath: string = path.join(workspaceRoot, TSCONFIG_FILENAME);
Promise.all([CordovaProjectHelper.exists(jsconfigPath), CordovaProjectHelper.exists(tsconfigPath)]).then(([jsExists, tsExists]) => {
if (!jsExists && !tsExists) {
fs.promises.writeFile(jsconfigPath, "{}").then(() => {
// Any open file must be reloaded to enable intellisense on them, so inform the user
vscode.window.showInformationMessage("A 'jsconfig.json' file was created to enable IntelliSense. You may need to reload your open JS file(s).");
});
}
});
}