<s>[INST] Evaluate $\int\limits_0^\pi \frac{\sin^2x}{2-\cos x}\ \mathrm dx$ by complex methods find integral $$\int\limits_0^\pi  \frac{\sin^2x}{2-\cos x}dx$$
what I had in mind is to use Euler formula, to turn it into a complex integral and change the limits of integration from $ -\pi$  to  $\pi$ so that any odd parts of the integrand would go to zero. But does not seem to make problem easier. Substitution of $u=\tan(x/2)$ would work but the computation is very tedious. Any suggestions for a nicer approach?  
 [/INST] Hint: Let $\gamma\colon [-\pi, \pi]\to \Bbb C, \theta \mapsto e^{i\theta}$. It is true that $\displaystyle \int \limits_0^ \pi\frac{(\sin(x))^2}{2-\cos(x)}\mathrm dx=\dfrac 1{4i}\int _\gamma \dfrac{z^4-2z^2+1}{z^4-4z^3+z^2}\mathrm dz$.
Further details: Note that for all $t\in \Bbb R$, $$\sin(t)=\dfrac{e^{it}-e^{-it}}{2i}\land \cos(t)=\dfrac{e^{it}+e^{-it}}{2}.$$
The map $x\mathop\longmapsto\dfrac{(\sin(x))^2}{2-\cos(x)}$ defined on $[-\pi, \pi]$ is even, thus $$\displaystyle \int \limits_{-\pi}^\pi\dfrac{(\sin(x))^2}{2-\cos(x)}\mathrm dx=2\int \limits_{0}^\pi\dfrac{(\sin(x))^2}{2-\cos(x)}\mathrm dx.$$
So,
$$\begin{align} \int \limits_{0}^\pi\dfrac{(\sin(x))^2}{2-\cos(x)}\mathrm dx&=\dfrac 1 2\int \limits_{-\pi}^\pi\dfrac{(\sin(x))^2}{2-\cos(x)}\mathrm dx\\
&=\dfrac 12\int \limits_{-\pi}^\pi\dfrac{\left(\frac{e^{ix}-e^{-ix}}{2i}\right)^2}{2-\frac{e^{ix}+e^{-ix}}{2}}\mathrm dx\\
\\&=\dfrac 12\int \limits_{-\pi}^\pi 1\cdot \dfrac{\frac{1}{-4}\left(e^{2ix}-2+e^{-2ix}\right)}{\frac{1}{2}\left(4-e^{ix}-e^{-ix}\right)}\mathrm dx\\
&=-\dfrac 1 {4}\int \limits_{-\pi}^\pi \dfrac{ie^{ix}}{ie^{ix}}\cdot \dfrac{e^{2ix}-2+e^{-2ix}}{4-e^{ix}-e^{-ix}}\mathrm dx\\
&=-\dfrac 1 {4i}\int \limits_{-\pi}^\pi \dfrac{\left(e^{2ix}-2+e^{-2ix}\right)ie^{ix}}{4e^{ix}-e^{2ix}-1}\mathrm dx\\ &=\dfrac 1 {4i}\int \limits_{-\pi}^\pi \dfrac{\left((e^{ix})^2-2+(e^{ix})^{-2}\right)ie^{ix}}{(e^{ix})^2-4e^{ix}+1}\mathrm dx\\ 
&=\dfrac 1 {4i}\int \limits_\gamma \dfrac{z^2-2+z^{-2}}{z^2-4+1}\mathrm dz\\
&=\dfrac 1 {4i}\int \limits_\gamma \dfrac{z^4-2z^2+1}{z^4-4z^3+z^2}\mathrm dz.\end{align}$$
The integral $\displaystyle \dfrac 1 {4i}\int \limits_\gamma \dfrac{z^4-2z^2+1}{z^4-4z^3+z^2}\mathrm dz$ can be found using residues.
It holds that for all $z\in \Bbb C$, $z^4-4z^3+z^2=z^2\left(z-(2-\sqrt 3)\right)\left(z-(2+\sqrt 3)\right)$.
Wolfram Alpha yields
$$\begin{align} &\operatorname{Res}\left(z\mapsto \dfrac{z^4-2z^2+1}{z^4-4z^3+z^2}, 0\right)&=4\\
&\operatorname{Res}\left(z\mapsto \dfrac{z^4-2z^2+1}{z^4-4z^3+z^2}, 2-\sqrt 3\right)&=-2\sqrt 3\\
&\operatorname{Res}\left(z\mapsto \dfrac{z^4-2z^2+1}{z^4-4z^3+z^2}, 2+\sqrt 3\right)&=2\sqrt 3.\end{align}$$
Since the winding numbers of the poles $2+\sqrt 3, 2-\sqrt 3$ and $0$ with respect to $\gamma$ are respectively $0, 1$ and $1$ it comes
$$\dfrac 1 {4i}\int \limits_\gamma \dfrac{z^4-2z^2+1}{z^4-4z^3+z^2}\mathrm dz=\dfrac 1{4i}\cdot 2\pi i\left(4-2\sqrt 3\right)=\pi(2-\sqrt 3).$$
</s>